diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 5156e30d7f..9e0a5feeda 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -1,3 +1,5 @@ Spree::Product.class_eval do belongs_to :supplier + + attr_accessible :supplier_id end \ No newline at end of file diff --git a/spec/request/distributors_spec.rb b/spec/request/distributors_spec.rb index 4ddb377093..0d85d277a5 100644 --- a/spec/request/distributors_spec.rb +++ b/spec/request/distributors_spec.rb @@ -5,6 +5,7 @@ feature %q{ I want manage the distributors of products } do include AuthenticationWorkflow + include WebHelper background do end @@ -33,7 +34,7 @@ feature %q{ click_button 'Create' - find('.flash').text.strip.should == 'Distributor "Eaterprises" has been successfully created!' + flash_message.should == 'Distributor "Eaterprises" has been successfully created!' end end end diff --git a/spec/request/product_spec.rb b/spec/request/product_spec.rb index 4ed426e64c..b64a1ec4a4 100644 --- a/spec/request/product_spec.rb +++ b/spec/request/product_spec.rb @@ -4,33 +4,30 @@ feature %q{ As a supplier I want set a supplier for a product } do - # include AuthenticationWorkflow - # include WebHelper + include AuthenticationWorkflow + include WebHelper background do - # @booking = Booking.make_booking - # @product_manager = User.make(:product_manager) + @supplier = Spree::Supplier.make!(:name => 'New supplier') end - context "Given I am editing a booking" do - scenario "I should be able to add a new note", :js =>true do - # user = Factory(:admin_user, :email => "c@example.com") - # sign_in_as!(user) + context "Given I am creating a Product" do + scenario "I should be able to assign a supplier to the Product" do + login_to_admin_section - # visit spree.admin_path - # click_link 'New Product' - # page.should have_content 'Notes' - # fill_in 'booking_note_comment', :with => 'A new note !!!' - # click_button 'Add note' + click_link 'Products' + click_link 'New Product' - # #flash_message.should == 'Booking Note successfully created.' + fill_in 'product_name', :with => 'A new product !!!' + fill_in 'product_price', :with => '19.99' + select('New supplier', :from => 'product_supplier_id') - # within('.notes-list') do - # page.should have_content('A new note !!!') - # page.should have_content(@product_manager.name) - # end - # click_link 'Back to Dashboard' - # page.should have_content 'Booking details' + click_button 'Create' + + flash_message.should == 'Product "A new product !!!" has been successfully created!' + Spree::Product.find_by_name('A new product !!!').supplier.should == @supplier end end + + context "Given I am cloning a Product" end diff --git a/spec/request/suppliers_spec.rb b/spec/request/suppliers_spec.rb index a19be159e3..0cb5ecc137 100644 --- a/spec/request/suppliers_spec.rb +++ b/spec/request/suppliers_spec.rb @@ -5,6 +5,7 @@ feature %q{ I want manage the suppliers of products } do include AuthenticationWorkflow + include WebHelper background do end @@ -29,7 +30,7 @@ feature %q{ click_button 'Create' - find('.flash').text.strip.should == 'Supplier "David arnold" has been successfully created!' + flash_message.should == 'Supplier "David arnold" has been successfully created!' end end end diff --git a/spec/support/blueprints.rb b/spec/support/blueprints.rb index 9b5cf3fd2c..e35b2abbc2 100644 --- a/spec/support/blueprints.rb +++ b/spec/support/blueprints.rb @@ -2,8 +2,15 @@ require 'machinist/active_record' # Add your blueprints here. # -# e.g. -# Post.blueprint do -# title { "Post #{sn}" } -# body { "Lorem ipsum..." } -# end +Spree::Supplier.blueprint do + name { "Supplier" } + description { 'supplier ' } + email { 'email@somewhere.com' } + twitter { '' } + website { '' } + address { '4 McDougal Rd' } + city { 'Austinvale' } + postcode { '2312' } + state { Spree::State.find_by_name('Victoria') } + country { Spree::Country.find_by_name('Australia') } +end diff --git a/spec/support/request/web_helper.rb b/spec/support/request/web_helper.rb new file mode 100644 index 0000000000..3c649b07c0 --- /dev/null +++ b/spec/support/request/web_helper.rb @@ -0,0 +1,92 @@ +module WebHelper + def current_path_should_be path + current_path = URI.parse(current_url).path + current_path.should == path + end + + def fill_in_fields(field_values) + field_values.each do |key, value| + begin + fill_in key, :with => value + rescue Capybara::ElementNotFound + find_field(key).select(value) + end + end + end + + def should_have_failed + page.status_code.should == 200 + errors.count.should > 0 + end + + def successful? + page.status_code.should == 200 + errors.count.should == 0 + flash_message.should include 'successful' + end + + def updated_field(field, value) + wait_for_ajax + yield(field, value) + rescue Capybara::TimeoutError + flunk "Expected #{field} to update to #{value}." + end + + def updated_css(css) + wait_for_ajax + yield(css) + rescue Capybara::TimeoutError + flunk "Expected updated css: #{css}." + end + + def user_nav + find('div.user/div.name').text + end + + def flash_message + find('.flash').text.strip + end + + def errors + all('.error') + end + + def property_name + find('.property-name').text + end + + def error_messages + errors.map(&:text) + end + + def handle_js_confirm(accept=true, debug=false) + page.evaluate_script "window.confirm = function(msg) { return #{!!accept }; }" + yield + end + + def handle_webdriver_random_failure(retry_times = 3) + begin + yield + rescue Selenium::WebDriver::Error::InvalidSelectorError => e + e.message =~ /nsIDOMXPathEvaluator.createNSResolver/ ? (retry if (retry_times -= 1 ) > 0) : raise + end + end + + def click_dialog_button(button_content) + page.find(:xpath, "//div[@class=\"ui-dialog-buttonset\"]//span[contains(text(),\"#{button_content}\")]").click + end + + def trigger_manual_event(field_selector, event = 'change') + page.execute_script("$('#{field_selector}').trigger('#{event}');") + end + + def dirty_form_dialog + DirtyFormDialog.new(page) + end + + private + def wait_for_ajax + wait_until { page.evaluate_script("$.active") == 0 } + end +end +