From 85297bed4fe0cf2fc76d2b7a435cfebdfdb84874 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Sun, 15 Dec 2013 17:55:14 +0100 Subject: [PATCH] Start supplier product category speccing --- .../product_categories_controller.rb | 4 +-- .../product_categories/index.html.slim | 2 +- .../product_category_generation.feature | 18 ++++++++++ .../suppliers/product_category_steps.rb | 34 +++++++++++++++++++ .../suppliers/product_steps.rb | 4 +++ 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 spec/acceptance/suppliers/product_category_generation.feature create mode 100644 spec/acceptance_steps/suppliers/product_category_steps.rb create mode 100644 spec/acceptance_steps/suppliers/product_steps.rb diff --git a/app/controllers/suppliers/product_categories_controller.rb b/app/controllers/suppliers/product_categories_controller.rb index 4abad56d..c6162788 100644 --- a/app/controllers/suppliers/product_categories_controller.rb +++ b/app/controllers/suppliers/product_categories_controller.rb @@ -47,7 +47,7 @@ module Suppliers respond_to do |format| if @product_category.save - format.html { redirect_to [:suppliers, @product_category], notice: t('action.create.successfull', model: ProductCategory.model_name.human) } + format.html { redirect_to [:suppliers, :product_categories], notice: t('action.create.successfull', model: ProductCategory.model_name.human) } format.json { render json: @product_category, status: :created, location: @product_category } else format.html { render action: "new" } @@ -63,7 +63,7 @@ module Suppliers respond_to do |format| if @product_category.update_attributes(params[:product_category]) - format.html { redirect_to [:suppliers, @product_category], 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 } else format.html { render action: "edit" } diff --git a/app/views/suppliers/product_categories/index.html.slim b/app/views/suppliers/product_categories/index.html.slim index 5d17a1fc..69e1a444 100644 --- a/app/views/suppliers/product_categories/index.html.slim +++ b/app/views/suppliers/product_categories/index.html.slim @@ -9,7 +9,7 @@ span.name= link_to product_category.name, [:suppliers, product_category] span= product_category.visible_on .pull-right.actions - = link_to t('helpers.links.edit'), [:edit, :suppliers, product_category], class: 'btn btn-mini' + = link_to t('helpers.links.edit'), [:edit, :suppliers, product_category], class: 'btn btn-mini edit-resource-button' ' = link_to t("helpers.links.destroy"), [:suppliers, product_category], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger' - else diff --git a/spec/acceptance/suppliers/product_category_generation.feature b/spec/acceptance/suppliers/product_category_generation.feature new file mode 100644 index 00000000..a11097c5 --- /dev/null +++ b/spec/acceptance/suppliers/product_category_generation.feature @@ -0,0 +1,18 @@ +Feature: Adding product category + + @javascript + Scenario: Adding a product category + Given there is a confirmed and open supplier + And I am signed in as supplier + And there are 2 supplier products + And the supplier visits the new product category page + And the supplier fills in the new product category form selecting the first product and available on tuesdays + When the supplier submits the product category form + Then then new product category with proper properties linked to the first product should have been created + And the supplier should be on the product categoy overview path + When the supplier clicks on the edit product category button + And the supplier unchecks the first product and checks the product + And the supplier clicks on the tuesday and wednesday buttons selecting wednesday as active day + And the supplier submits the product category form + + diff --git a/spec/acceptance_steps/suppliers/product_category_steps.rb b/spec/acceptance_steps/suppliers/product_category_steps.rb new file mode 100644 index 00000000..aa2841ca --- /dev/null +++ b/spec/acceptance_steps/suppliers/product_category_steps.rb @@ -0,0 +1,34 @@ + +step "the supplier visits the new product category page" do + visit new_suppliers_product_category_path +end + +step "the supplier fills in the new product category form selecting the first product and available on tuesdays" do + find('#product_category_name').set 'New product category' + find("#product-checker-#{@products.first.id}").set true + page.all('.week-day-toggle').each do |day_toggle| + next if day_toggle['data-day'] == 'tuesday' + day_toggle.click + end +end +step "the supplier submits the product category form" do + submit_form +end + +step "then new product category with proper properties linked to the first product should have been created" do + sleep 1 + @product_category = ProductCategory.find_by_name 'New product category' + @product_category.week_days.should == [0, 0, 1, 0, 0, 0, 0] + @product_category.full_day.should be_true + @product_category.product_ids.should == [@products.first.id] +end + +step "the supplier should be on the product categoy overview path" do + route_should_be "suppliers/product_categories#index" +end + +step "the supplier clicks on the edit product category button" do + within "#product_category_#{@product_category.id}" do + find('.edit-resource-button').click + end +end diff --git a/spec/acceptance_steps/suppliers/product_steps.rb b/spec/acceptance_steps/suppliers/product_steps.rb new file mode 100644 index 00000000..0e92eddf --- /dev/null +++ b/spec/acceptance_steps/suppliers/product_steps.rb @@ -0,0 +1,4 @@ + +step "there are :count supplier products" do |count| + @products = create_list :product, count.to_i, supplier: @supplier +end