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
+2 -2
View File
@@ -71,8 +71,8 @@ group :test do
gem 'rspec-rails' gem 'rspec-rails'
gem 'database_cleaner' gem 'database_cleaner'
gem 'capybara' #, '2.0.3' gem 'capybara' #, '2.0.3'
gem 'selenium-webdriver' #gem 'selenium-webdriver'
#gem 'capybara-webkit', '~>0.14.2' # version 1.1.0 does not yet compile in mavericks gem 'capybara-webkit' #, '~>0.14.2' # version 1.1.0 does not yet compile in mavericks
gem 'turnip' gem 'turnip'
gem 'launchy' gem 'launchy'
gem 'fuubar' gem 'fuubar'
+12 -19
View File
@@ -99,8 +99,9 @@ GEM
rack (>= 1.0.0) rack (>= 1.0.0)
rack-test (>= 0.5.4) rack-test (>= 0.5.4)
xpath (~> 2.0) xpath (~> 2.0)
childprocess (0.3.9) capybara-webkit (1.1.0)
ffi (~> 1.0, >= 1.0.11) capybara (~> 2.0, >= 2.0.2)
json
chunky_png (1.2.9) chunky_png (1.2.9)
climate_control (0.0.3) climate_control (0.0.3)
activesupport (>= 3.0) activesupport (>= 3.0)
@@ -182,20 +183,19 @@ GEM
faye-websocket (0.7.1) faye-websocket (0.7.1)
eventmachine (>= 0.12.0) eventmachine (>= 0.12.0)
websocket-driver (>= 0.3.1) websocket-driver (>= 0.3.1)
ffi (1.9.3)
fssm (0.2.10) fssm (0.2.10)
fuubar (1.3.0) fuubar (1.3.2)
rspec (>= 2.14.0, < 3.1.0) rspec (>= 2.14.0, < 3.1.0)
ruby-progressbar (~> 1.3) ruby-progressbar (~> 1.3)
gherkin (2.12.2) gherkin (2.12.2)
multi_json (~> 1.3) multi_json (~> 1.3)
haml (4.0.4) haml (4.0.4)
tilt tilt
haml-rails (0.5.2) haml-rails (0.5.3)
actionpack (~> 4.0.1) actionpack (>= 4.0.1)
activesupport (~> 4.0.1) activesupport (>= 4.0.1)
haml (>= 3.1, < 5.0) haml (>= 3.1, < 5.0)
railties (~> 4.0.1) railties (>= 4.0.1)
handlebars-source (1.1.2) handlebars-source (1.1.2)
hashie (2.0.5) hashie (2.0.5)
hike (1.2.3) hike (1.2.3)
@@ -277,7 +277,7 @@ GEM
activesupport (= 4.0.2) activesupport (= 4.0.2)
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rake (10.1.0) rake (10.1.1)
rest-client (1.6.7) rest-client (1.6.7)
mime-types (>= 1.16) mime-types (>= 1.16)
rqrcode (0.4.2) rqrcode (0.4.2)
@@ -297,17 +297,11 @@ GEM
rspec-expectations (~> 2.14.0) rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0) rspec-mocks (~> 2.14.0)
ruby-progressbar (1.3.2) ruby-progressbar (1.3.2)
rubyzip (1.1.0) sass (3.2.13)
sass (3.2.12)
sass-rails (4.0.1) sass-rails (4.0.1)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
sass (>= 3.1.10) sass (>= 3.1.10)
sprockets-rails (~> 2.0.0) sprockets-rails (~> 2.0.0)
selenium-webdriver (2.38.0)
childprocess (>= 0.2.5)
multi_json (~> 1.0)
rubyzip (~> 1.0)
websocket (~> 1.0.4)
simple_form (3.0.1) simple_form (3.0.1)
actionpack (>= 4.0.0, < 4.1) actionpack (>= 4.0.0, < 4.1)
activemodel (>= 4.0.0, < 4.1) activemodel (>= 4.0.0, < 4.1)
@@ -348,12 +342,11 @@ GEM
gherkin (>= 2.5) gherkin (>= 2.5)
rspec (~> 2.0) rspec (~> 2.0)
tzinfo (0.3.38) tzinfo (0.3.38)
uglifier (2.3.3) uglifier (2.4.0)
execjs (>= 0.3.0) execjs (>= 0.3.0)
json (>= 1.8.0) json (>= 1.8.0)
warden (1.2.3) warden (1.2.3)
rack (>= 1.0) rack (>= 1.0)
websocket (1.0.7)
websocket-driver (0.3.1) websocket-driver (0.3.1)
xpath (2.0.0) xpath (2.0.0)
nokogiri (~> 1.3) nokogiri (~> 1.3)
@@ -366,6 +359,7 @@ DEPENDENCIES
bootstrap-sass (~> 2.3.2.2) bootstrap-sass (~> 2.3.2.2)
bourbon bourbon
capybara capybara
capybara-webkit
cmtool! cmtool!
coffee-rails coffee-rails
compass-rails compass-rails
@@ -395,7 +389,6 @@ DEPENDENCIES
rqrcode rqrcode
rspec-rails rspec-rails
sass-rails sass-rails
selenium-webdriver
simple_form simple_form
simply_stored! simply_stored!
slim-rails slim-rails
@@ -73,7 +73,7 @@ module Suppliers
# POST /lists # POST /lists
# POST /lists.json # POST /lists.json
def create def create
@list = List.new(params[:list]) @list = List.new(list_params)
@list.supplier = current_supplier @list.supplier = current_supplier
respond_to do |format| respond_to do |format|
@@ -102,7 +102,7 @@ module Suppliers
@list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) @list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
respond_to do |format| respond_to do |format|
if @list.update_attributes(params[:list]) if @list.update_attributes(list_params)
format.html { redirect_to [:suppliers, @list], notice: t('action.update.successfull', model: List.model_name.human) } format.html { redirect_to [:suppliers, @list], notice: t('action.update.successfull', model: List.model_name.human) }
format.json { head :no_content } format.json { head :no_content }
format.js { head :no_content } format.js { head :no_content }
@@ -126,5 +126,11 @@ module Suppliers
format.json { head :no_content } format.json { head :no_content }
end end
end end
private
def list_params
params.require(:list).permit(:state, :needs_help, :needs_payment, :closed_at, :join_requests, :price, :is_paid, :paid_at, :table_id, :section_id)
end
end end
end end
@@ -42,7 +42,7 @@ module Suppliers
# POST /product_categories # POST /product_categories
# POST /product_categories.json # POST /product_categories.json
def create def create
@product_category = ProductCategory.new(params[:product_category]) @product_category = ProductCategory.new(product_category_params)
@product_category.supplier = current_supplier @product_category.supplier = current_supplier
respond_to do |format| respond_to do |format|
@@ -62,7 +62,7 @@ module Suppliers
@product_category = ProductCategory.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) @product_category = ProductCategory.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
respond_to do |format| respond_to do |format|
if @product_category.update_attributes(params[:product_category]) if @product_category.update_attributes(product_category_params)
format.html { redirect_to [:suppliers, :product_categories], notice: t('action.update.successfull', model: ProductCategory.model_name.human) } format.html { redirect_to [:suppliers, :product_categories], notice: t('action.update.successfull', model: ProductCategory.model_name.human) }
format.json { head :no_content } format.json { head :no_content }
else else
@@ -92,5 +92,11 @@ module Suppliers
CouchPotato.database.couchrest_database.bulk_save(@product_categories) CouchPotato.database.couchrest_database.bulk_save(@product_categories)
render nothing: true render nothing: true
end end
private
def product_category_params
params.require(:product_category).permit(:name, :start_from, :end_on, :full_day, product_ids: [], week_days: [])
end
end end
end end
@@ -43,12 +43,12 @@ module Suppliers
# POST /products # POST /products
# POST /products.json # POST /products.json
def create def create
@product = Product.new(params[:product]) @product = Product.new(product_params)
@product.supplier = current_supplier @product.supplier = current_supplier
respond_to do |format| respond_to do |format|
if @product.save if @product.save
format.html { redirect_to [:suppliers, @product], notice: t('action.create.successfull', model: Product.model_name.human) } format.html { redirect_to [:suppliers, :products], notice: t('action.create.successfull', model: Product.model_name.human) }
format.json { render json: @product, status: :created, location: @product } format.json { render json: @product, status: :created, location: @product }
else else
format.html { render action: "new" } format.html { render action: "new" }
@@ -63,8 +63,8 @@ module Suppliers
@product = Product.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) @product = Product.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
respond_to do |format| respond_to do |format|
if @product.update_attributes(params[:product]) if @product.update_attributes(product_params)
format.html { redirect_to [:suppliers, @product], notice: t('action.update.successfull', model: Product.model_name.human) } format.html { redirect_to [:suppliers, :products], notice: t('action.update.successfull', model: Product.model_name.human) }
format.json { head :no_content } format.json { head :no_content }
else else
format.html { render action: "edit" } format.html { render action: "edit" }
@@ -90,5 +90,11 @@ module Suppliers
product_categories = ProductCategory.for_supplier_in_time(current_supplier, @time) product_categories = ProductCategory.for_supplier_in_time(current_supplier, @time)
render json: {categories: product_categories.map(&:to_client_format).select(&:present?)} render json: {categories: product_categories.map(&:to_client_format).select(&:present?)}
end end
private
def product_params
params.require(:product).permit(:name, :code, :price, product_category_ids: [])
end
end end
end end
@@ -54,7 +54,7 @@ module Suppliers
# POST /sections # POST /sections
# POST /sections.json # POST /sections.json
def create def create
@section = Section.new(params[:section]) @section = Section.new(section_params)
@section.supplier = current_supplier @section.supplier = current_supplier
respond_to do |format| respond_to do |format|
@@ -74,7 +74,7 @@ module Suppliers
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) @section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
respond_to do |format| respond_to do |format|
if @section.update_attributes(params[:section]) if @section.update_attributes(section_params)
format.html { redirect_to [:suppliers, @section], notice: t('action.update.successfull', model: Section.model_name.human) } format.html { redirect_to [:suppliers, @section], notice: t('action.update.successfull', model: Section.model_name.human) }
format.json { head :no_content } format.json { head :no_content }
else else
@@ -157,5 +157,11 @@ module Suppliers
@orders = @list ? @list.active_orders : [] @orders = @list ? @list.active_orders : []
render layout: false render layout: false
end end
private
def section_params
params.require(:section).permit(:title, :path, :width, :height)
end
end end
end end
@@ -43,7 +43,7 @@ module Suppliers
# POST /tables # POST /tables
# POST /tables.json # POST /tables.json
def create def create
@table = Table.new(params[:table]) @table = Table.new(table_params)
@table.supplier = current_supplier @table.supplier = current_supplier
respond_to do |format| respond_to do |format|
@@ -63,8 +63,8 @@ module Suppliers
@table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) @table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
respond_to do |format| respond_to do |format|
if @table.update_attributes(params[:table]) if @table.update_attributes(table_params)
format.html { redirect_to [:suppliers, @table], notice: t('action.update.successfull', model: Table.model_name.human) } format.html { redirect_to [:suppliers, @table.section || @table], notice: t('action.update.successfull', model: Table.model_name.human) }
format.json { head :no_content } format.json { head :no_content }
format.js { head :no_content } format.js { head :no_content }
else else
@@ -92,5 +92,11 @@ module Suppliers
@tables.select!{|t| t.section_id == params[:section_id]} if params[:section_id].present? @tables.select!{|t| t.section_id == params[:section_id]} if params[:section_id].present?
render layout: 'qr_sheet' render layout: 'qr_sheet'
end end
private
def table_params
params.require(:table).permit(:number, :section_id, :position_x, :position_y)
end
end end
end end
+15 -5
View File
@@ -21,15 +21,25 @@ class Product
def product_category_ids=(ids) def product_category_ids=(ids)
@product_category_ids = ids.select(&:present?) @product_category_ids = ids.select(&:present?)
is_dirty
end end
private private
def persist_product_category_ids def persist_product_category_ids
return unless @product_category_ids.present? @product_category_ids ||= []
database.load(@product_category_ids).each do |product_category| existing_product_categories = product_categories
product_category.product_ids ||= []
product_category.product_ids |= [id] # do nothing if nothing has changed
product_category.save return if @product_category_ids == existing_product_categories.map(&:id)
# clear removed product categories
existing_product_categories.reject{|pc| @product_category_ids.include?(pc.id) }.each{|pc| pc.remove_product(self) }
# Add product to newly added product categories
database.load(@product_category_ids - existing_product_categories.map(&:id)).each do |product_category|
product_category.add_product(self)
end end
end end
+1
View File
@@ -130,6 +130,7 @@ class Section
end end
return saves.all? return saves.all?
end end
def arrange_tables_in_columns_of(n) def arrange_tables_in_columns_of(n)
return unless n.present? return unless n.present?
n = n.to_i n = n.to_i
+1 -1
View File
@@ -13,6 +13,6 @@
br br
.form-actions .form-actions
= f.button :submit, class: 'btn-primary' = f.button :submit, class: 'btn-primary save-product-button'
' '
= link_to t("helpers.links.cancel"), suppliers_products_path, class: 'btn' = link_to t("helpers.links.cancel"), suppliers_products_path, class: 'btn'
+2 -2
View File
@@ -14,14 +14,14 @@
th.actions data-t="helpers.actions.title" =t 'helpers.actions.title' th.actions data-t="helpers.actions.title" =t 'helpers.actions.title'
tbody tbody
- @products.each do |product| - @products.each do |product|
tr tr class="product-row-#{product.id}"
td.link= link_to product.name, [:suppliers, product] td.link= link_to product.name, [:suppliers, product]
td= product.code td= product.code
td.currency=currency product.price td.currency=currency product.price
td.link= product.category_links namespace: :suppliers td.link= product.category_links namespace: :suppliers
td.timestamp data-time=product.created_at.utc.iso8601 td.timestamp data-time=product.created_at.utc.iso8601
td.actions td.actions
= link_to t('helpers.links.edit'), [:edit, :suppliers, product], class: 'btn btn-mini' = link_to t('helpers.links.edit'), [:edit, :suppliers, product], class: 'btn btn-mini edit-resource-button'
' '
= link_to t("helpers.links.destroy"), [:suppliers, product], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger' = link_to t("helpers.links.destroy"), [:suppliers, product], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger'
- else - else
+1 -1
View File
@@ -9,6 +9,6 @@
.controls .controls
= f.collection_select :section_id, current_supplier.sections, :id, :title, include_blank: "[#{t('supplier.tables.has_no_section')}]" = f.collection_select :section_id, current_supplier.sections, :id, :title, include_blank: "[#{t('supplier.tables.has_no_section')}]"
.form-actions .form-actions
= f.submit nil, class: 'btn btn-primary' = f.submit nil, class: 'btn btn-primary save-table-button'
' '
= link_to t("helpers.links.cancel"), suppliers_tables_path, class: 'btn' = link_to t("helpers.links.cancel"), suppliers_tables_path, class: 'btn'
@@ -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.week_days.should == [0, 0, 0, 1, 0, 0, 0]
@product_category.product_ids.should == [@products.last.id] @product_category.product_ids.should == [@products.last.id]
end 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| step "there are :count supplier products" do |count|
@products = create_list :product, count.to_i, supplier: @supplier @products = create_list :product, count.to_i, supplier: @supplier
end 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 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 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 I18n.locale =I18n.default_locale
Devise.stretches = 1 Devise.stretches = 1
#Capybara.javascript_driver = :webkit Capybara.javascript_driver = :webkit
Capybara.javascript_driver = :selenium #Capybara.javascript_driver = :selenium
module FactoryAttributesFor module FactoryAttributesFor
def attributes_for(obj, options={}) def attributes_for(obj, options={})
@@ -27,20 +27,6 @@ module SpecSelectorHelpers
'.navbar-fixed-top' '.navbar-fixed-top'
end 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 # Uses the click_on method for capybara
def click_on_translation(key) def click_on_translation(key)
text = I18n.t(key) text = I18n.t(key)
+2 -1
View File
@@ -1,7 +1,7 @@
module SpecRouteHelpers module SpecRouteHelpers
# allows tests like: # allows tests like:
# route_should_be 'agama_groups#index' # route_should_be 'agama_groups#index'
def route_should_be(route_def) def route_should_be(route_def, options = {})
route_hash = case route_def route_hash = case route_def
when String when String
controller_name, action_name = route_def.split('#') controller_name, action_name = route_def.split('#')
@@ -10,6 +10,7 @@ module SpecRouteHelpers
else else
route_def route_def
end end
route_hash.merge! options
Rails.application.routes.recognize_path(page.current_path).should include route_hash Rails.application.routes.recognize_path(page.current_path).should include route_hash
end end
end end
+2541 -2
View File
File diff suppressed because one or more lines are too long