diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index 8977888475..4c0cf6d836 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -238,8 +238,23 @@ feature %q{ end - context "as an Enterprise user" do - context "when I have reached my enterprise ownership limit", js: true do + context "as an Enterprise user", js: true do + let(:supplier1) { create(:supplier_enterprise, name: 'First Supplier') } + let(:supplier2) { create(:supplier_enterprise, name: 'Another Supplier') } + let(:distributor1) { create(:distributor_enterprise, name: 'First Distributor') } + let(:distributor2) { create(:distributor_enterprise, name: 'Another Distributor') } + let(:distributor3) { create(:distributor_enterprise, name: 'Yet Another Distributor') } + let(:enterprise_user) { create_enterprise_user } + let!(:er) { create(:enterprise_relationship, parent: distributor3, child: distributor1, permissions_list: [:edit_profile]) } + + before(:each) do + enterprise_user.enterprise_roles.build(enterprise: supplier1).save + enterprise_user.enterprise_roles.build(enterprise: distributor1).save + + login_to_admin_as enterprise_user + end + + context "when I have reached my enterprise ownership limit" do it "does not display the link to create a new enterprise" do supplier1.reload enterprise_user.owned_enterprises.push [supplier1] @@ -293,7 +308,7 @@ feature %q{ scenario "editing enterprises I manage" do click_link 'Enterprises' - within("#listing_enterprises tr.enterprise-#{distributor1.id}") { click_link 'Edit Profile' } + within("tbody#e_#{distributor1.id}") { click_link 'Manage' } fill_in 'enterprise_name', :with => 'Eaterprises' click_button 'Update' @@ -305,7 +320,7 @@ feature %q{ describe "enterprises I have edit permission for, but do not manage" do it "allows me to edit them" do click_link 'Enterprises' - within("#listing_enterprises tr.enterprise-#{distributor3.id}") { click_link 'Edit Profile' } + within("tbody#e_#{distributor3.id}") { click_link 'Manage' } fill_in 'enterprise_name', :with => 'Eaterprises' click_button 'Update' @@ -314,18 +329,9 @@ feature %q{ distributor3.reload.name.should == 'Eaterprises' end - it "does not show links to manage shipping methods, payment methods or enterprise fees" do + it "does not show links to manage shipping methods, payment methods or enterprise fees on the edit page" do click_link 'Enterprises' - within("#listing_enterprises tr.enterprise-#{distributor3.id}") do - page.should_not have_link 'Shipping Methods' - page.should_not have_link 'Payment Methods' - page.should_not have_link 'Enterprise Fees' - end - end - - it "does not show links to manage shipping methods, payment methods or enterprise fees on the edit page", js: true do - click_link 'Enterprises' - within("#listing_enterprises tr.enterprise-#{distributor3.id}") { click_link 'Edit Profile' } + within("tbody#e_#{distributor3.id}") { click_link 'Manage' } within(".side_menu") do page.should_not have_link 'Shipping Methods' @@ -337,26 +343,35 @@ feature %q{ scenario "editing images for an enterprise" do click_link 'Enterprises' - first(".edit").click - page.should have_content "Logo" - page.should have_content "Promo" + within("tbody#e_#{distributor1.id}") { click_link 'Manage' } + + within(".side_menu") do + click_link "Images" + end + + page.should have_content "LOGO" + page.should have_content "PROMO" end - scenario "managing producer properties", js: true do + scenario "managing producer properties" do create(:property, name: "Certified Organic") click_link 'Enterprises' - within(".enterprise-#{supplier1.id}") { click_link 'Properties' } + within("#e_#{supplier1.id}") { click_link 'Manage' } + within(".side_menu") do + click_link "Properties" + end # -- Update only select2_select "Certified Organic", from: 'enterprise_producer_properties_attributes_0_property_name' fill_in 'enterprise_producer_properties_attributes_0_value', with: "NASAA 12345" click_button 'Update' - page.should have_selector '#listing_enterprises a', text: supplier1.name supplier1.producer_properties(true).count.should == 1 # -- Destroy pp = supplier1.producer_properties.first - within(".enterprise-#{supplier1.id}") { click_link 'Properties' } + within(".side_menu") do + click_link "Properties" + end within("#spree_producer_property_#{pp.id}") { page.find('a.remove_fields').click } page.should_not have_selector '#progress'