Added product request spec and fixed bug when setting supplier.

This commit is contained in:
Andrew Spinks
2012-06-10 16:54:38 +10:00
parent 92b55e6478
commit d089500a5e
6 changed files with 127 additions and 27 deletions

View File

@@ -1,3 +1,5 @@
Spree::Product.class_eval do
belongs_to :supplier
attr_accessible :supplier_id
end

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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