Merging master into this branch to keep repository up to date

This commit is contained in:
summerscope
2014-09-11 16:33:44 +10:00
27 changed files with 302 additions and 167 deletions

View File

@@ -24,5 +24,5 @@ angular.module("ofn.admin").factory 'EnterpriseRelationships', ($http, enterpris
permission_presentation: (permission) ->
switch permission
when "add_to_order_cycle" then "can add to order cycle"
when "manage_products" then "can manage the products of"
when "add_to_order_cycle" then "to add to order cycle"
when "manage_products" then "to manage products"

View File

@@ -6,9 +6,9 @@ Darkswarm.controller "CheckoutCtrl", ($scope, storage, Checkout, CurrentUser, Cu
prefix = "order_#{Checkout.order.id}#{CurrentUser?.id}#{CurrentHub.hub.id}"
for field in $scope.fieldsToBind
storage.bind $scope, "Checkout.order.#{field}",
storage.bind $scope, "Checkout.order.#{field}",
storeName: "#{prefix}_#{field}"
storage.bind $scope, "Checkout.ship_address_same_as_billing",
storage.bind $scope, "Checkout.ship_address_same_as_billing",
storeName: "#{prefix}_sameasbilling"
defaultValue: true

View File

@@ -13,7 +13,7 @@ Darkswarm.factory 'Checkout', (CurrentOrder, ShippingMethods, PaymentMethods, $h
Loading.clear()
@errors = response.errors
RailsFlashLoader.loadFlash(response.flash)
# Rails wants our Spree::Address data to be provided with _attributes
preprocess: ->
munged_order = {}
@@ -25,7 +25,7 @@ Darkswarm.factory 'Checkout', (CurrentOrder, ShippingMethods, PaymentMethods, $h
munged_order["ship_address_attributes"] = value
when "payment_method_id"
munged_order["payments_attributes"] = [{payment_method_id: value}]
when "shipping_method_id", "payment_method_id", "email"
when "shipping_method_id", "payment_method_id", "email", "special_instructions"
munged_order[name] = value
else
# Ignore everything else
@@ -58,7 +58,7 @@ Darkswarm.factory 'Checkout', (CurrentOrder, ShippingMethods, PaymentMethods, $h
shippingPrice: ->
@shippingMethod()?.price || 0.0
paymentMethod: ->
PaymentMethods.payment_methods_by_id[@order.payment_method_id]

View File

@@ -0,0 +1,3 @@
// https://docs.angularjs.org/api/ng/directive/ngCloak
[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak
display: none !important

View File

@@ -22,7 +22,7 @@
display: inline-block
margin-right: 0.25rem
float: left
//Closed & Open column
.open_closed
i
@@ -30,9 +30,8 @@
float: right
margin-left: 0.5rem
//Hub Name
//Hub Name
span.hub-name-listing
float: left
font-weight: 700
//CLOSED row
@@ -65,7 +64,7 @@
&.open
.active_table_row:nth-child(2)
padding-bottom: 0.75rem
//CURRENT hub (shows selected hub)
&.current
//overwrites active_table

View File

@@ -4,6 +4,8 @@ module Admin
before_filter :load_countries, :except => :index
before_filter :load_methods_and_fees, :only => [:new, :edit, :update, :create]
create.after :grant_management
before_filter :check_type, only: :update
before_filter :check_bulk_type, only: :bulk_update
helper 'spree/products'
include OrderCyclesHelper
@@ -67,6 +69,18 @@ module Admin
@enterprise_fees = EnterpriseFee.managed_by(spree_current_user).for_enterprise(@enterprise).order(:fee_type, :name).all
end
def check_bulk_type
unless spree_current_user.admin?
params[:enterprise_set][:collection_attributes].each do |i, enterprise_params|
enterprise_params.delete :type
end
end
end
def check_type
params[:enterprise].delete :type unless spree_current_user.admin?
end
# Overriding method on Spree's resource controller
def location_after_save
if params[:enterprise].key? :producer_properties_attributes

View File

@@ -9,7 +9,7 @@ class CheckoutController < Spree::CheckoutController
include OrderCyclesHelper
include EnterprisesHelper
def edit
# Because this controller doesn't inherit from our BaseController
# We need to duplicate the code here
@@ -56,7 +56,7 @@ class CheckoutController < Spree::CheckoutController
private
# Copied and modified from spree. Remove check for order state, since the state machine is
# progressed all the way in one go with the one page checkout.
def object_params
@@ -94,7 +94,7 @@ class CheckoutController < Spree::CheckoutController
def skip_state_validation?
true
end
def load_order
@order = current_order
redirect_to main_app.shop_path and return unless @order and @order.checkout_allowed?
@@ -112,6 +112,14 @@ class CheckoutController < Spree::CheckoutController
@order.ship_address ||= preferred_ship_address || last_used_ship_address || Spree::Address.default
end
def after_payment
# object_params sets the payment amount to the order total, but it does this before
# the shipping method is set. This results in the customer not being charged for their
# order's shipping. To fix this, we refresh the payment amount here.
@order.update_totals
@order.payments.first.update_attribute :amount, @order.total
end
# Overriding Spree's methods
def raise_insufficient_quantity
flash[:error] = t(:spree_inventory_error_flash_for_insufficient_quantity)

View File

@@ -8,6 +8,7 @@ module Spree
klass = klass_for_without_sym_fallback(name)
klass ||= name.singularize.to_sym
klass = :overview if klass == :dashboard
klass = Spree::Order if klass == :bulk_order_management
klass
end
alias_method_chain :klass_for, :sym_fallback

View File

@@ -1,7 +1,7 @@
class EnterpriseRelationship < ActiveRecord::Base
belongs_to :parent, class_name: 'Enterprise', touch: true
belongs_to :child, class_name: 'Enterprise', touch: true
has_many :permissions, class_name: 'EnterpriseRelationshipPermission'
has_many :permissions, class_name: 'EnterpriseRelationshipPermission', dependent: :destroy
validates_presence_of :parent_id, :child_id
validates_uniqueness_of :child_id, scope: :parent_id, message: "^That relationship is already established."

View File

@@ -59,12 +59,12 @@ class AbilityDecorator
# Enterprise User can only access orders that they are a distributor for
can [:index, :create], Spree::Order
can [:read, :update, :bulk_management, :fire, :resend], Spree::Order do |order|
can [:read, :update, :fire, :resend], Spree::Order do |order|
# We allow editing orders with a nil distributor as this state occurs
# during the order creation process from the admin backend
order.distributor.nil? || user.enterprises.include?(order.distributor)
end
can [:admin], Spree::Order if user.admin? || user.enterprises.any?(&:is_distributor?)
can [:admin, :bulk_management], Spree::Order if user.admin? || user.enterprises.any?(&:is_distributor?)
can [:admin, :create], Spree::LineItem
can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Payment

View File

@@ -17,6 +17,9 @@ end
class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer
attributes :orders_close_at, :active
#TODO: Remove these later
attributes :icon, :has_shopfront, :can_aggregate
def orders_close_at
OrderCycle.first_closing_for(object).andand.orders_close_at
end
@@ -24,51 +27,10 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer
def active
@options[:active_distributors].andand.include? object
end
end
class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
cached
delegate :cache_key, to: :object
attributes :name, :id, :description, :latitude, :longitude,
:long_description, :website, :instagram, :linkedin, :twitter,
:facebook, :is_primary_producer, :is_distributor, :phone, :visible,
:email, :hash, :logo, :promo_image, :icon, :path,
:pickup, :delivery
attributes :has_shopfront, :can_aggregate
has_many :distributed_taxons, key: :taxons, serializer: Api::IdSerializer
has_many :supplied_taxons, serializer: Api::IdSerializer
has_many :distributors, key: :hubs, serializer: Api::IdSerializer
has_many :suppliers, key: :producers, serializer: Api::IdSerializer
has_one :address, serializer: Api::AddressSerializer
def pickup
object.shipping_methods.where(:require_ship_address => false).present?
end
def delivery
object.shipping_methods.where(:require_ship_address => true).present?
end
def email
object.email.to_s.reverse
end
def hash
object.to_param
end
def logo
object.logo(:medium) if object.logo.exists?
end
def promo_image
object.promo_image(:large) if object.promo_image.exists?
end
# TODO: Move this back to uncached section when relavant properties are defined on the Enterprise model
def icon
# TODO: Replace with object.has_shopfront when this property exists
if has_shopfront
if can_aggregate
"/assets/map_005-hub.svg"
@@ -101,6 +63,48 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
def can_aggregate
object.is_distributor && object.suppliers != [object]
end
end
class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
cached
delegate :cache_key, to: :object
attributes :name, :id, :description, :latitude, :longitude,
:long_description, :website, :instagram, :linkedin, :twitter,
:facebook, :is_primary_producer, :is_distributor, :phone, :visible,
:email, :hash, :logo, :promo_image, :path,
:pickup, :delivery
has_many :distributed_taxons, key: :taxons, serializer: Api::IdSerializer
has_many :supplied_taxons, serializer: Api::IdSerializer
has_many :distributors, key: :hubs, serializer: Api::IdSerializer
has_many :suppliers, key: :producers, serializer: Api::IdSerializer
has_one :address, serializer: Api::AddressSerializer
def pickup
object.shipping_methods.where(:require_ship_address => false).present?
end
def delivery
object.shipping_methods.where(:require_ship_address => true).present?
end
def email
object.email.to_s.reverse
end
def hash
object.to_param
end
def logo
object.logo(:medium) if object.logo.exists?
end
def promo_image
object.promo_image(:large) if object.promo_image.exists?
end
# TODO when ActiveSerializers supports URL helpers
# Then refactor. See readme https://github.com/rails-api/active_model_serializers

View File

@@ -1,8 +1,10 @@
%td {{ enterprise_relationship.child_name }}
%td
%ul
%li{"ng-repeat" => "permission in enterprise_relationship.permissions"}
{{ EnterpriseRelationships.permission_presentation(permission.name) }}
%td {{ enterprise_relationship.parent_name }}
%td.actions
%a.delete-enterprise-relationship.icon-trash.no-text{'ng-click' => 'delete(enterprise_relationship)'}
%tr{"ng-repeat" => "enterprise_relationship in EnterpriseRelationships.enterprise_relationships | filter:query"}
%td {{ enterprise_relationship.parent_name }}
%td permits
%td {{ enterprise_relationship.child_name }}
%td
%ul
%li{"ng-repeat" => "permission in enterprise_relationship.permissions"}
{{ EnterpriseRelationships.permission_presentation(permission.name) }}
%td.actions
%a.delete-enterprise-relationship.icon-trash.no-text{'ng-click' => 'delete(enterprise_relationship)'}

View File

@@ -1,4 +1,9 @@
%tr
%td
%select{name: "enterprise_relationship_parent_id", "ng-model" => "parent_id", "ng-options" => "e.id as e.name for e in Enterprises.my_enterprises"}
%td
permits
%td
%select{name: "enterprise_relationship_child_id", "ng-model" => "child_id", "ng-options" => "e.id as e.name for e in Enterprises.all_enterprises"}
%td
@@ -6,8 +11,6 @@
%label
%input{type: "checkbox", "ng-model" => "permissions[permission]"}
{{ EnterpriseRelationships.permission_presentation(permission) }}
%td
%select{name: "enterprise_relationship_parent_id", "ng-model" => "parent_id", "ng-options" => "e.id as e.name for e in Enterprises.my_enterprises"}
%td.actions
%input{type: "button", value: "Create", "ng-click" => "create()"}
.errors {{ EnterpriseRelationships.create_errors }}

View File

@@ -11,5 +11,4 @@
%table#enterprise-relationships
%tbody
= render 'form'
%tr{"ng-repeat" => "enterprise_relationship in EnterpriseRelationships.enterprise_relationships | filter:query"}
= render 'enterprise_relationship'
= render 'enterprise_relationship'

View File

@@ -36,24 +36,25 @@
= f.check_box :is_primary_producer, 'ng-model' => 'Enterprise.is_primary_producer'
&nbsp;
= f.label :is_primary_producer, 'Producer'
.row
.alpha.eleven.columns
.three.columns.alpha
= f.label :type, 'Profile type'
.with-tip{'data-powertip' => "Full - enterprise may have products and relationships.<br />Single - enterprise may have products but no relationships.<br />Profile - enterprise has a profile but no products or relationships.<br />"}
%a What's this?
.two.columns
= f.radio_button :type, "full"
&nbsp;
= f.label :type, "Full", value: "full"
.two.columns
= f.radio_button :type, "single"
&nbsp;
= f.label :type, "Single", value: "single"
.four.columns.omega
= f.radio_button :type, "profile"
&nbsp;
= f.label :type, "Profile", value: "profile"
- if spree_current_user.admin?
.row
.alpha.eleven.columns
.three.columns.alpha
= f.label :type, 'Profile type'
.with-tip{'data-powertip' => "Full - enterprise may have products and relationships.<br />Single - enterprise may have products but no relationships.<br />Profile - enterprise has a profile but no products or relationships.<br />"}
%a What's this?
.two.columns
= f.radio_button :type, "full"
&nbsp;
= f.label :type, "Full", value: "full"
.two.columns
= f.radio_button :type, "single"
&nbsp;
= f.label :type, "Single", value: "single"
.four.columns.omega
= f.radio_button :type, "profile"
&nbsp;
= f.label :type, "Profile", value: "profile"
.row
.three.columns.alpha
%label Visible in search?

View File

@@ -10,17 +10,17 @@
= form_for @enterprise_set, :url => main_app.bulk_update_admin_enterprises_path do |f|
%table#listing_enterprises.index
%colgroup
%col{style: "width: 20%;"}/
%col{style: "width: 25%;"}/
%col{style: "width: 10%;"}/
%col{style: "width: 5%;"}/
%col/
%col{style: "width: 10%;"}/
%col{style: "width: 20%;"}/
%thead
%tr{"data-hook" => "enterprises_header"}
%th Name
%th Role
%th Visible?
%th Description
%th Type
%th
%tbody
= f.fields_for :collection do |enterprise_form|
@@ -28,16 +28,13 @@
%tr{class: "enterprise-#{enterprise.id}"}
%td= link_to enterprise.name, main_app.edit_admin_enterprise_path(enterprise)
%td
- if enterprise.is_primary_producer && enterprise.is_distributor
Producer &amp; Distributor
- elsif enterprise.is_distributor
Distributor
- elsif enterprise.is_primary_producer
Producer
- else
%h1.icon-exclamation-sign.with-tip{"data-powertip" => "This enterprise does not have any roles", style: "text-align: center;color: #DA5354"}
= enterprise_form.check_box :is_primary_producer
Producer
%br/
= enterprise_form.check_box :is_distributor
Hub
%td= enterprise_form.check_box :visible
%td= enterprise.description
%td= enterprise_form.select :type, Enterprise::TYPES, {}, class: 'select2 fullwidth'
%td{"data-hook" => "admin_users_index_row_actions"}
= render 'actions', enterprise: enterprise
- if @enterprises.empty?

View File

@@ -1,8 +1,8 @@
= f_form_for current_order, url: main_app.update_checkout_path,
= f_form_for current_order,
html: {name: "checkout",
id: "checkout_form",
novalidate: true,
name: "checkout"} do |f|
"ng-submit" => "purchase($event)"} do |f|
= inject_available_shipping_methods
= inject_available_payment_methods
@@ -20,7 +20,6 @@
= render partial: "checkout/payment", locals: {f: f}
%p
%button.button.primary{type: :submit,
"ng-click" => "purchase($event)",
"ng-disabled" => "checkout.$invalid"}
Place order now
/ {{ checkout.$valid }}

View File

@@ -4,16 +4,17 @@
%h1= image_tag "ofn_logo_beta.png", title: "Open Food Network (beta)"
%h2 An open marketplace that makes it easy to find, buy, sell and move sustainable local food.
%ofn-modal{title: "Learn more"}
%ofn-modal{title: "Learn more", "ng-cloak" => true}
= render partial: "modals/learn_more"
= render partial: "home/hubs"
.ng-cloak
= render partial: "home/hubs"
/ = render partial: "home/map"
/ = render partial: "home/map"
/ = render partial: "home/producers"
/ = render partial: "home/producers"
/ = render partial: "home/groups"
/ = render partial: "home/groups"
= render partial: "home/beta"

View File

@@ -32,10 +32,10 @@
- else
= render 'shared/signed_in'
%li.divider
%li.current_hub{"ng-controller" => "CurrentHubCtrl", "ng-show" => "CurrentHub.hub.id"}
%li.current_hub{"ng-controller" => "CurrentHubCtrl", "ng-show" => "CurrentHub.hub.id", "ng-cloak" => true}
%a{href: main_app.shop_path}
%em Shopping &#64;
%span.nav-primary.nav-branded {{ CurrentHub.hub.name }}
%li.divider
%li.cart
%li.cart{"ng-cloak" => true}
= render partial: "shared/menu/cart"

View File

@@ -7,7 +7,7 @@ feature %q{
}, skip: true do
include AuthenticationWorkflow
include WebHelper
background do
set_feature_toggle :order_cycles, true
@@ -24,8 +24,8 @@ feature %q{
:state => Spree::State.find_by_name('Victoria'),
:country => Spree::Country.find_by_name('Australia')),
:pickup_times => 'Tuesday, 4 PM')
@distributor_alternative = create(:distributor_enterprise, :name => 'Alternative Distributor',
:address => create(:address,
:address1 => '1600 Rathdowne St',
@@ -33,7 +33,7 @@ feature %q{
:zipcode => 3054,
:state => Spree::State.find_by_name('Victoria'),
:country => Spree::Country.find_by_name('Australia')),
:pickup_times => 'Tuesday, 4 PM')
:pickup_times => 'Tuesday, 4 PM')
@enterprise_fee_1 = create(:enterprise_fee, :name => 'Enterprise Fee One', :calculator => Spree::Calculator::PerItem.new)
@enterprise_fee_1.calculator.set_preference :amount, 1
@@ -347,16 +347,16 @@ feature %q{
login_to_consumer_section
click_link 'FruitAndVeg'
visit enterprise_path @distributor1
visit enterprise_path @distributor1
click_link 'Bananas'
click_button 'Add To Cart'
visit enterprise_path @distributor1
visit enterprise_path @distributor1
click_link 'Zucchini'
click_button 'Add To Cart'
find('#checkout-link').click
# And manually visit the old checkout
visit "/checkout"
@@ -389,7 +389,7 @@ feature %q{
# -- Checkout: Delivery
page.should have_content "DELIVERY METHOD"
order_charges = page.all("tbody#summary-order-charges tr").map {|row| row.all('td').map(&:text)}.take(2)
order_charges.should == [["Distribution:", "$51.00"]]
order_charges.should == [["Distribution:", "$51.00"]]
click_checkout_continue_button
@@ -403,7 +403,7 @@ feature %q{
# -- Checkout: Order complete
page.should have_content 'Your order has been processed successfully'
page.should have_content @payment_method_distributor_oc.description
page.should have_content @distributor_oc.name
page.should have_content @distributor_oc.name
page.should have_selector 'tfoot#order-charges tr.total td', text: 'Distribution'
page.should have_selector 'tfoot#order-charges tr.total td', text: '51.00'

View File

@@ -36,5 +36,67 @@ module Admin
admin_user.enterprise_roles.where(enterprise_id: enterprise).should be_empty
end
end
describe "updating an enterprise" do
let(:profile_enterprise) { create(:enterprise, type: 'profile') }
context "as manager" do
it "does not allow 'type' to be changed" do
profile_enterprise.enterprise_roles.build(user: user).save
controller.stub spree_current_user: user
enterprise_params = { id: profile_enterprise.id, enterprise: { type: 'full' } }
spree_put :update, enterprise_params
profile_enterprise.reload
expect(profile_enterprise.type).to eq 'profile'
end
end
context "as super admin" do
it "allows 'type' to be changed" do
controller.stub spree_current_user: admin_user
enterprise_params = { id: profile_enterprise.id, enterprise: { type: 'full' } }
spree_put :update, enterprise_params
profile_enterprise.reload
expect(profile_enterprise.type).to eq 'full'
end
end
end
describe "bulk updating enterprises" do
let(:profile_enterprise1) { create(:enterprise, type: 'profile') }
let(:profile_enterprise2) { create(:enterprise, type: 'profile') }
context "as manager" do
it "does not allow 'type' to be changed" do
profile_enterprise1.enterprise_roles.build(user: user).save
profile_enterprise2.enterprise_roles.build(user: user).save
controller.stub spree_current_user: user
bulk_enterprise_params = { enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, type: 'full' }, '1' => { id: profile_enterprise2.id, type: 'full' } } } }
spree_put :bulk_update, bulk_enterprise_params
profile_enterprise1.reload
profile_enterprise2.reload
expect(profile_enterprise1.type).to eq 'profile'
expect(profile_enterprise2.type).to eq 'profile'
end
end
context "as super admin" do
it "allows 'type' to be changed" do
profile_enterprise1.enterprise_roles.build(user: user).save
profile_enterprise2.enterprise_roles.build(user: user).save
controller.stub spree_current_user: admin_user
bulk_enterprise_params = { enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, type: 'full' }, '1' => { id: profile_enterprise2.id, type: 'full' } } } }
spree_put :bulk_update, bulk_enterprise_params
profile_enterprise1.reload
profile_enterprise2.reload
expect(profile_enterprise1.type).to eq 'full'
expect(profile_enterprise2.type).to eq 'full'
end
end
end
end
end

View File

@@ -15,13 +15,6 @@ feature %q{
admin_user = quick_login_as_admin
end
it "displays a Bulk Management Tab under the Orders item" do
visit '/admin/orders'
page.should have_link "Bulk Order Management"
click_link "Bulk Order Management"
page.should have_selector "h1.page-title", text: "Bulk Order Management"
end
it "displays a message when number of line items is zero" do
visit '/admin/orders/bulk_management'
page.should have_text "No orders found."
@@ -586,6 +579,13 @@ feature %q{
quick_login_as @enterprise_user
end
it "displays a Bulk Management Tab under the Orders item" do
visit '/admin/orders'
page.should have_link "Bulk Order Management"
click_link "Bulk Order Management"
page.should have_selector "h1.page-title", text: "Bulk Order Management"
end
it "shows only line item from orders that I distribute, and not those that I supply" do
visit '/admin/orders/bulk_management'

View File

@@ -24,10 +24,10 @@ feature %q{
# Then I should see the relationships
within('table#enterprise-relationships') do
page.should have_relationship e1, e2, ['can add to order cycle']
page.should have_relationship e2, e3, ['can manage the products of']
page.should have_relationship e1, e2, ['to add to order cycle']
page.should have_relationship e2, e3, ['to manage products']
page.should have_relationship e3, e4,
['can add to order cycle', 'can manage the products of']
['to add to order cycle', 'to manage products']
end
end
@@ -39,13 +39,13 @@ feature %q{
visit admin_enterprise_relationships_path
select 'One', from: 'enterprise_relationship_parent_id'
check 'can add to order cycle'
check 'can manage the products of'
uncheck 'can manage the products of'
check 'to add to order cycle'
check 'to manage products'
uncheck 'to manage products'
select 'Two', from: 'enterprise_relationship_child_id'
click_button 'Create'
page.should have_relationship e1, e2, ['can add to order cycle']
page.should have_relationship e1, e2, ['to add to order cycle']
er = EnterpriseRelationship.where(parent_id: e1, child_id: e2).first
er.should be_present
er.permissions.map(&:name).should == ['add_to_order_cycle']
@@ -69,14 +69,13 @@ feature %q{
end.to change(EnterpriseRelationship, :count).by(0)
end
scenario "deleting a relationship" do
e1 = create(:enterprise, name: 'One')
e2 = create(:enterprise, name: 'Two')
er = create(:enterprise_relationship, parent: e1, child: e2)
er = create(:enterprise_relationship, parent: e1, child: e2, permissions_list: [:add_to_order_cycle])
visit admin_enterprise_relationships_path
page.should have_relationship e1, e2
page.should have_relationship e1, e2, ['to add to order cycle']
first("a.delete-enterprise-relationship").click
@@ -118,8 +117,8 @@ feature %q{
private
def have_relationship(parent, child, perms=[])
perms = perms.join(' ') || 'permits'
perms = perms.join(' ')
have_table_row [child.name, perms, parent.name, '']
have_table_row [parent.name, 'permits', child.name, perms, '']
end
end

View File

@@ -15,39 +15,43 @@ feature %q{
click_link 'Enterprises'
within("tr.enterprise-#{s.id}") do
page.should have_content s.name
page.should have_content "Edit Profile"
page.should have_content "Delete"
page.should_not have_content "Payment Methods"
page.should_not have_content "Shipping Methods"
page.should have_content "Enterprise Fees"
expect(page).to have_content s.name
expect(page).to have_select "enterprise_set_collection_attributes_1_type"
expect(page).to have_content "Edit Profile"
expect(page).to have_content "Delete"
expect(page).to_not have_content "Payment Methods"
expect(page).to_not have_content "Shipping Methods"
expect(page).to have_content "Enterprise Fees"
end
within("tr.enterprise-#{d.id}") do
page.should have_content d.name
page.should have_content "Edit Profile"
page.should have_content "Delete"
page.should have_content "Payment Methods"
page.should have_content "Shipping Methods"
page.should have_content "Enterprise Fees"
expect(page).to have_content d.name
expect(page).to have_select "enterprise_set_collection_attributes_0_type"
expect(page).to have_content "Edit Profile"
expect(page).to have_content "Delete"
expect(page).to have_content "Payment Methods"
expect(page).to have_content "Shipping Methods"
expect(page).to have_content "Enterprise Fees"
end
end
scenario "editing enterprises in bulk" do
s = create(:supplier_enterprise)
d = create(:distributor_enterprise)
d = create(:distributor_enterprise, type: 'profile')
login_to_admin_section
click_link 'Enterprises'
within("tr.enterprise-#{d.id}") do
page.should have_checked_field "enterprise_set_collection_attributes_0_visible"
expect(page).to have_checked_field "enterprise_set_collection_attributes_0_visible"
uncheck "enterprise_set_collection_attributes_0_visible"
select 'full', from: "enterprise_set_collection_attributes_0_type"
end
click_button "Update"
flash_message.should == 'Enterprises updated successfully'
distributor = Enterprise.find(d.id)
distributor.visible.should == false
expect(distributor.visible).to eq false
expect(distributor.type).to eq 'full'
end
scenario "viewing an enterprise" do
@@ -127,7 +131,7 @@ feature %q{
choose 'Single'
fill_in 'enterprise_description', :with => 'Connecting farmers and eaters'
fill_in 'enterprise_long_description', :with => 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro.'
# Check Angularjs switching of sidebar elements
uncheck 'enterprise_is_primary_producer'
uncheck 'enterprise_is_distributor'
@@ -259,10 +263,22 @@ feature %q{
click_link "Enterprises"
page.should have_content supplier1.name
page.should have_content distributor1.name
page.should_not have_content supplier2.name
page.should_not have_content distributor2.name
within("tr.enterprise-#{distributor1.id}") do
expect(page).to have_content distributor1.name
expect(page).to have_checked_field "enterprise_set_collection_attributes_0_is_distributor"
expect(page).to have_unchecked_field "enterprise_set_collection_attributes_0_is_primary_producer"
expect(page).to have_select "enterprise_set_collection_attributes_0_type"
end
within("tr.enterprise-#{supplier1.id}") do
expect(page).to have_content supplier1.name
expect(page).to have_unchecked_field "enterprise_set_collection_attributes_1_is_distributor"
expect(page).to have_checked_field "enterprise_set_collection_attributes_1_is_primary_producer"
expect(page).to have_select "enterprise_set_collection_attributes_1_type"
end
expect(page).to_not have_content "supplier2.name"
expect(page).to_not have_content "distributor2.name"
end
scenario "creating an enterprise" do

View File

@@ -94,10 +94,6 @@ feature "As a consumer I want to check out my cart", js: true do
describe "purchasing" do
it "takes us to the order confirmation page when we submit a complete form" do
toggle_shipping
choose sm2.name
toggle_payment
choose pm1.name
toggle_details
within "#details" do
fill_in "First Name", with: "Will"
@@ -112,14 +108,25 @@ feature "As a consumer I want to check out my cart", js: true do
select "Victoria", from: "State"
fill_in "City", with: "Melbourne"
fill_in "Postcode", with: "3066"
end
toggle_shipping
within "#shipping" do
choose sm2.name
fill_in 'Any notes or custom delivery instructions?', with: "SpEcIaL NoTeS"
end
toggle_payment
within "#payment" do
choose pm1.name
end
place_order
page.should have_content "Your order has been processed successfully"
ActionMailer::Base.deliveries.length.should == 2
email = ActionMailer::Base.deliveries.last
site_name = Spree::Config[:site_name]
email.subject.should include "#{site_name} Order Confirmation"
o = Spree::Order.complete.first
expect(o.special_instructions).to eq "SpEcIaL NoTeS"
end
context "with basic details filled" do
@@ -152,6 +159,20 @@ feature "As a consumer I want to check out my cart", js: true do
page.should have_content "Your order has been processed successfully"
end
context "when we are charged a shipping fee" do
before { choose sm2.name }
it "creates a payment for the full amount inclusive of shipping" do
place_order
page.should have_content "Your order has been processed successfully"
# There are two orders - our order and our new cart
o = Spree::Order.complete.first
o.adjustments.shipping.first.amount.should == 4.56
o.payments.first.amount.should == 10 + 1.23 + 4.56 # items + fees + shipping
end
end
context "with a credit card payment method" do
let!(:pm1) { create(:payment_method, distributors: [distributor], name: "Roger rabbit", type: "Spree::Gateway::Bogus") }
@@ -167,7 +188,7 @@ feature "As a consumer I want to check out my cart", js: true do
# Order should have a payment with the correct amount
o = Spree::Order.complete.first
o.payments.first.amount.should == 11.23
o.payments.first.amount.should == 15.79
end
it "shows the payment processing failed message when submitted with an invalid credit card" do

View File

@@ -15,6 +15,10 @@ module Spree
it "returns :overview for the dashboard" do
helper.klass_for('dashboard').should == :overview
end
it "returns Spree::Order for bulk_order_management" do
helper.klass_for('bulk_order_management').should == Spree::Order
end
end
end
end

View File

@@ -4,7 +4,9 @@ describe Spree::ProductFilters do
context "distributor filter" do
it "provides filtering for all distributors" do
3.times { create(:distributor_enterprise) }
Spree::ProductFilters.distributor_filter[:labels].should == Enterprise.is_distributor.sort.map { |d| [d.name, d.name] }
Enterprise.is_distributor.sort.map { |d| [d.name, d.name] }.each do |distributor|
expect(Spree::ProductFilters.distributor_filter[:labels]).to include distributor
end
end
end
end