updating part2, far from finished

This commit is contained in:
2013-12-20 19:22:12 +01:00
parent 748944865d
commit b4c4a15e60
22 changed files with 2779 additions and 62 deletions
@@ -0,0 +1,18 @@
Feature: Adding product
Scenario: Adding a product
Given there is a confirmed and open supplier
And I am signed in as supplier
And there are 2 supplier product categories
And the supplier visits the new product page
And the supplier fills in the new product form selecting the first product category
When the supplier submits the product form
Then the new product with proper properties linked to the first product category should have been created
And the supplier should be on the product overview path
When the supplier clicks on the edit product button
And the supplier unchecks the first product category and checks the last product category
And the supplier submits the product form
Then the supplier product should only be linked to the last product category
And the supplier should be on the product overview path
@@ -0,0 +1,18 @@
Feature: Adding product
Scenario: Adding a product
Given there is a confirmed and open supplier
And I am signed in as supplier
And there are 2 supplier sections
And the supplier visits the new table page
And the supplier fills in the new table form selecting the first section
When the supplier submits the table form
Then the new supplier table with proper properties should have been created
And the supplier should be on the table section page
When the supplier visits the edit table page
And the supplier changes the table number to 9 and section to the last section
And the supplier submits the table form
Then the supplier table should have number 9 and be linked to the last section
And the supplier should be on the table section page
@@ -49,3 +49,7 @@ step "the the product category is active on wednesday and only linked to the las
@product_category.week_days.should == [0, 0, 0, 1, 0, 0, 0]
@product_category.product_ids.should == [@products.last.id]
end
step "there are :count supplier product categories" do |count|
@product_categories = create_list :product_category, count.to_i, supplier: @supplier
end
@@ -1,4 +1,50 @@
step "the supplier visits the new product page" do
visit new_suppliers_product_path
end
step "there are :count supplier products" do |count|
@products = create_list :product, count.to_i, supplier: @supplier
end
step "the supplier fills in the new product form selecting the first product category" do
find('#product_name').set 'New product'
find('#product_code').set 'NL0487'
find('#product_price').set '6.42'
find("#product-category-checker-#{@product_categories.first.id}").set true
end
step "the supplier submits the product form" do
find('.save-product-button').click
end
step "the new product with proper properties linked to the first product category should have been created" do
sleep 1
@product = Product.find_by_name 'New product'
@product.code.should == 'NL0487'
@product.price.should == 6.42
@product_categories.each(&:reload)
@product.product_categories.should == [@product_categories.first]
end
step "the supplier should be on the product overview path" do
route_should_be 'suppliers/products#index'
end
step "the supplier clicks on the edit product button" do
within ".product-row-#{@product.id}" do
find('.edit-resource-button').click
end
end
step "the supplier unchecks the first product category and checks the last product category" do
find("#product-category-checker-#{@product_categories.first.id}").set false
find("#product-category-checker-#{@product_categories.last.id}").set true
end
step "the supplier product should only be linked to the last product category" do
@product.reload
@product_categories.each(&:reload)
@product.product_categories.should == [@product_categories.last]
end
@@ -0,0 +1,3 @@
step "there are 2 supplier sections" do
@sections = create_list :section, 2, supplier: @supplier
end
@@ -0,0 +1,40 @@
step "the supplier visits the new table page" do
visit new_suppliers_table_path
end
step "the supplier fills in the new table form selecting the first section" do
find('#table_number').set '7'
section_option = find(%|option[value="#{@sections.first.id}"]|)
select section_option.text, from: 'table_section_id'
end
step "the supplier submits the table form" do
find('.save-table-button').click
end
step "the new supplier table with proper properties should have been created" do
@table = Table.find_by_number 7
@table.section_id.should == @sections.first.id
end
step "the supplier should be on the table section page" do
@table.reload
route_should_be 'suppliers/sections#show', id: @table.section_id
end
step "the supplier visits the edit table page" do
visit edit_suppliers_table_path(@table)
end
step "the supplier changes the table number to :number and section to the last section" do |number|
find('#table_number').set number
section_option = find(%|option[value="#{@sections.last.id}"]|)
select section_option.text, from: 'table_section_id'
end
step "the supplier table should have number :number and be linked to the last section" do |number|
@table.reload
@table.number.should == number.to_i
@table.section_id.should == @sections.last.id
end
+28
View File
@@ -2,5 +2,33 @@ require 'spec_helper'
describe Product do
describe 'update product category through ids' do
it 'works' do
supplier = create :supplier
pc1 = create :product_category, supplier: supplier
pc2 = create :product_category, supplier: supplier
product = build :product, supplier: supplier, product_category_ids: [pc1.id]
product.save.should be_true
product.reload
pc1.reload
pc2.reload
pc1.product_ids.should == [product.id]
pc2.product_ids.should_not be_present
product.update_attributes product_category_ids: [pc2.id]
product.reload
pc1.reload
pc2.reload
product.product_categories.should == [pc2]
# empty set also works
product.update_attributes product_category_ids: ['']
product.reload
product.product_categories.should be_empty
end
end
end
+2 -16
View File
@@ -14,8 +14,8 @@ Dir.glob("spec/acceptance_steps/**/*steps.rb") { |f| load f, true }
I18n.locale =I18n.default_locale
Devise.stretches = 1
#Capybara.javascript_driver = :webkit
Capybara.javascript_driver = :selenium
Capybara.javascript_driver = :webkit
#Capybara.javascript_driver = :selenium
module FactoryAttributesFor
def attributes_for(obj, options={})
@@ -27,20 +27,6 @@ module SpecSelectorHelpers
'.navbar-fixed-top'
end
# allows tests like:
# route_should_be 'agama_groups#index'
def route_should_be(route_def)
route_hash = case route_def
when String
controller_name, action_name = route_def.split('#')
#action_name = 'index' unless action_name.present?
{controller: controller_name, action: action_name}
else
route_def
end
Rails.application.routes.recognize_path(page.current_path).should include route_hash
end
# Uses the click_on method for capybara
def click_on_translation(key)
text = I18n.t(key)
+2 -1
View File
@@ -1,7 +1,7 @@
module SpecRouteHelpers
# allows tests like:
# route_should_be 'agama_groups#index'
def route_should_be(route_def)
def route_should_be(route_def, options = {})
route_hash = case route_def
when String
controller_name, action_name = route_def.split('#')
@@ -10,6 +10,7 @@ module SpecRouteHelpers
else
route_def
end
route_hash.merge! options
Rails.application.routes.recognize_path(page.current_path).should include route_hash
end
end