From 1a394c6061935e9ef3d39c1ad88378cf872630f7 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Tue, 29 Mar 2016 09:14:59 -0700 Subject: [PATCH 01/25] Cucumber tests for category bug --- features/manage_articles.feature | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 features/manage_articles.feature diff --git a/features/manage_articles.feature b/features/manage_articles.feature new file mode 100644 index 0000000000..4ec6dd168b --- /dev/null +++ b/features/manage_articles.feature @@ -0,0 +1,13 @@ +Feature: Manage Articles + In order to organize articles + As an admin + I want to add a new category + + Background: + Given the blog is set up + And I am logged into the admin panel + + Scenario: Create category page is shown + Given I am on the admin page + When I follow "Categories" + Then I should be on the add/edit category page From 04dee8711933ca91f285f38d8c3be98da359f0b5 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Tue, 29 Mar 2016 09:15:54 -0700 Subject: [PATCH 02/25] Add pry gem --- Gemfile | 1 + Gemfile.lock | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index b8121c7ee5..771ddb6ce7 100644 --- a/Gemfile +++ b/Gemfile @@ -57,4 +57,5 @@ group :development, :test do gem 'cucumber-rails-training-wheels' gem 'database_cleaner' gem 'capybara' + gem 'pry' end diff --git a/Gemfile.lock b/Gemfile.lock index 64eb36cc1c..26794b0ec3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,5 @@ GEM - remote: http://rubygems.org/ + remote: https://rubygems.org/ specs: RedCloth (4.2.9) abstract (1.0.0) @@ -87,6 +87,8 @@ GEM i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) + method_source (0.6.7) + ruby_parser (>= 2.3.1) mime-types (1.19) mini_magick (1.3.3) subexec (~> 0.0.4) @@ -94,6 +96,11 @@ GEM nokogiri (1.5.5) pg (0.14.1) polyglot (0.3.3) + pry (0.9.7.4) + coderay (~> 0.9.8) + method_source (~> 0.6.7) + ruby_parser (>= 2.3.1) + slop (~> 2.1.0) rack (1.2.5) rack-mount (0.6.14) rack (>= 1.0.0) @@ -141,6 +148,8 @@ GEM ruby-debug-base19 (>= 0.11.19) ruby_core_source (0.1.5) archive-tar-minitar (>= 0.5.2) + ruby_parser (3.8.1) + sexp_processor (~> 4.1) rubypants (0.2.0) rubyzip (0.9.9) selenium-webdriver (2.25.0) @@ -148,10 +157,12 @@ GEM libwebsocket (~> 0.1.3) multi_json (~> 1.0) rubyzip + sexp_processor (4.7.0) simplecov (0.6.4) multi_json (~> 1.0) simplecov-html (~> 0.5.3) simplecov-html (0.5.3) + slop (2.1.0) sqlite3 (1.3.6) subexec (0.0.4) thin (1.5.0) @@ -193,6 +204,7 @@ DEPENDENCIES kaminari mini_magick (~> 1.3.3) pg + pry rails (~> 3.0.10) rake (~> 0.9.2) recaptcha @@ -205,3 +217,6 @@ DEPENDENCIES thin uuidtools (~> 2.1.1) webrat + +BUNDLED WITH + 1.11.2 From 2d27732cea9262ca0133aca1acf061df72678d89 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Tue, 29 Mar 2016 09:16:35 -0700 Subject: [PATCH 03/25] Update paths for admin page --- features/support/paths.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/features/support/paths.rb b/features/support/paths.rb index e7e00e5d89..895d83f048 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -17,6 +17,8 @@ def path_to(page_name) '/' when /^the new article page$/ '/admin/content/new' + when /^the admin page$/ + '/admin' # Add more mappings here. # Here is an example that pulls values out of the Regexp: From d7825eccefe1eeaf4cb10dafe4b476c3a912e824 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Tue, 29 Mar 2016 09:55:02 -0700 Subject: [PATCH 04/25] fix new or edit method using case - where if id is nill create a new category, else find that category to edit --- app/controllers/admin/categories_controller.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/categories_controller.rb b/app/controllers/admin/categories_controller.rb index b7026f8f29..7a04df9507 100644 --- a/app/controllers/admin/categories_controller.rb +++ b/app/controllers/admin/categories_controller.rb @@ -4,10 +4,10 @@ class Admin::CategoriesController < Admin::BaseController def index; redirect_to :action => 'new' ; end def edit; new_or_edit; end - def new + def new respond_to do |format| format.html { new_or_edit } - format.js { + format.js { @category = Category.new } end @@ -25,12 +25,17 @@ def destroy def new_or_edit @categories = Category.find(:all) - @category = Category.find(params[:id]) + @category = case params[:id] + when nil + Category.new + else + Category.find(params[:id]) + end @category.attributes = params[:category] if request.post? respond_to do |format| format.html { save_category } - format.js do + format.js do @category.save @article = Article.new @article.categories << @category From a58edb8e1cb66e070e130c11e4a8914eca735f1a Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Tue, 29 Mar 2016 10:02:45 -0700 Subject: [PATCH 05/25] working cucumber tests for clicking Categories link on admin panel --- features/manage_articles.feature | 2 +- features/support/paths.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/features/manage_articles.feature b/features/manage_articles.feature index 4ec6dd168b..4334c118ba 100644 --- a/features/manage_articles.feature +++ b/features/manage_articles.feature @@ -10,4 +10,4 @@ Feature: Manage Articles Scenario: Create category page is shown Given I am on the admin page When I follow "Categories" - Then I should be on the add/edit category page + Then I should be on the new or edit category page diff --git a/features/support/paths.rb b/features/support/paths.rb index 895d83f048..dc570fe6eb 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -19,6 +19,8 @@ def path_to(page_name) '/admin/content/new' when /^the admin page$/ '/admin' + when /^the new or edit category page$/ + '/admin/categories/new' # Add more mappings here. # Here is an example that pulls values out of the Regexp: From caede3bd035f61e2a4a39c20d6c8855f9317bbf2 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Tue, 29 Mar 2016 10:59:51 -0700 Subject: [PATCH 06/25] passing rspec test for clicking on categories link on admin panel --- spec/controllers/admin/categories_controller_spec.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/spec/controllers/admin/categories_controller_spec.rb b/spec/controllers/admin/categories_controller_spec.rb index bb290f4a0d..3a4a554fc5 100644 --- a/spec/controllers/admin/categories_controller_spec.rb +++ b/spec/controllers/admin/categories_controller_spec.rb @@ -16,6 +16,11 @@ assert_response :redirect, :action => 'index' end + it "test_new" do + get :new + assert_template 'new' + end + describe "test_edit" do before(:each) do get :edit, :id => Factory(:category).id @@ -48,7 +53,7 @@ it 'should render destroy template' do assert_response :success - assert_template 'destroy' + assert_template 'destroy' end end @@ -62,5 +67,5 @@ assert_raise(ActiveRecord::RecordNotFound) { Category.find(test_id) } end - + end From ba17a5275f71c3a97d11b9a9403e9c59fa5866e5 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Tue, 29 Mar 2016 11:16:19 -0700 Subject: [PATCH 07/25] cucumber test for creating a new category --- features/manage_categories.feature | 19 +++++++++++++++++++ features/support/paths.rb | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 features/manage_categories.feature diff --git a/features/manage_categories.feature b/features/manage_categories.feature new file mode 100644 index 0000000000..453da3d2d5 --- /dev/null +++ b/features/manage_categories.feature @@ -0,0 +1,19 @@ +Feature: Manage Categories + In order to better organize articles + As an admin + I want to add a new category + + Background: + Given the blog is set up + And I am logged into the admin panel + + Scenario: Create category page is shown + Given I am on the admin page + When I follow "Categories" + Then I should be on the new category page + + Scenario: Create valid category + Given I am on the new category page + When I fill in "category_name" with "mishmash" + And I press "Save" + Then I should see "Category was successfully saved." diff --git a/features/support/paths.rb b/features/support/paths.rb index dc570fe6eb..2cc0bddee1 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -19,7 +19,7 @@ def path_to(page_name) '/admin/content/new' when /^the admin page$/ '/admin' - when /^the new or edit category page$/ + when /^the new category page$/ '/admin/categories/new' # Add more mappings here. From 6bfd744440ab0de4824765ef89d03a8dbcc836c1 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Tue, 29 Mar 2016 11:32:50 -0700 Subject: [PATCH 08/25] cucumber test to check if category count increases by 1 when new category is added --- features/manage_categories.feature | 2 ++ features/step_definitions/web_steps.rb | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/features/manage_categories.feature b/features/manage_categories.feature index 453da3d2d5..434dc182b2 100644 --- a/features/manage_categories.feature +++ b/features/manage_categories.feature @@ -17,3 +17,5 @@ Feature: Manage Categories When I fill in "category_name" with "mishmash" And I press "Save" Then I should see "Category was successfully saved." + And I should see "mishmash" + And I should have 1 new category diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index 6315105872..f72b997bce 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -162,6 +162,13 @@ def with_scope(locator) end end +Then /^I should have (\d+) new category$/ do |count| + # pending # express the regexp above with the code you wish you had + # expect{Category.count}.to change{Category.count}.by(arg1) + Category.count.should == count.to_i + 1 +end + + Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value| with_scope(parent) do field = find_field(field) @@ -250,7 +257,7 @@ def with_scope(locator) end end end - + Then /^(?:|I )should be on (.+)$/ do |page_name| current_path = URI.parse(current_url).path if current_path.respond_to? :should @@ -264,8 +271,8 @@ def with_scope(locator) query = URI.parse(current_url).query actual_params = query ? CGI.parse(query) : {} expected_params = {} - expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')} - + expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')} + if actual_params.respond_to? :should actual_params.should == expected_params else From 2119aa1b907ccc353f99f8d7bd5c06fceaa5d437 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Tue, 29 Mar 2016 11:41:48 -0700 Subject: [PATCH 09/25] modify cucumber category scenario to test edit --- features/manage_categories.feature | 12 +++++++----- features/support/paths.rb | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/features/manage_categories.feature b/features/manage_categories.feature index 434dc182b2..a5a45aa0c4 100644 --- a/features/manage_categories.feature +++ b/features/manage_categories.feature @@ -1,21 +1,23 @@ Feature: Manage Categories In order to better organize articles As an admin - I want to add a new category + I want to add or edit a category Background: Given the blog is set up And I am logged into the admin panel - Scenario: Create category page is shown + Scenario: Category page is shown Given I am on the admin page When I follow "Categories" - Then I should be on the new category page + Then I should be on the category page - Scenario: Create valid category - Given I am on the new category page + Scenario: Create and edit category + Given I am on the category page When I fill in "category_name" with "mishmash" And I press "Save" Then I should see "Category was successfully saved." And I should see "mishmash" And I should have 1 new category + When I follow "mishmash" + Then I should see "mishmash" diff --git a/features/support/paths.rb b/features/support/paths.rb index 2cc0bddee1..9c5eb20802 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -19,7 +19,7 @@ def path_to(page_name) '/admin/content/new' when /^the admin page$/ '/admin' - when /^the new category page$/ + when /^the category page$/ '/admin/categories/new' # Add more mappings here. From 72f97da6191c4591ca9d6abf905b9e39ca894a8f Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Tue, 29 Mar 2016 11:47:55 -0700 Subject: [PATCH 10/25] modify category new rspec --- spec/controllers/admin/categories_controller_spec.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spec/controllers/admin/categories_controller_spec.rb b/spec/controllers/admin/categories_controller_spec.rb index 3a4a554fc5..57a009eeff 100644 --- a/spec/controllers/admin/categories_controller_spec.rb +++ b/spec/controllers/admin/categories_controller_spec.rb @@ -16,9 +16,14 @@ assert_response :redirect, :action => 'index' end - it "test_new" do - get :new - assert_template 'new' + describe "test_new" do + before(:each) do + Category.new + end + it "should render template new" do + get :new + assert_template 'new' + end end describe "test_edit" do From 50f981651e2794253b392dfb3679b6f01ad45bd5 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Tue, 29 Mar 2016 12:03:14 -0700 Subject: [PATCH 11/25] modify new category rspec --- spec/controllers/admin/categories_controller_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/controllers/admin/categories_controller_spec.rb b/spec/controllers/admin/categories_controller_spec.rb index 57a009eeff..355319a231 100644 --- a/spec/controllers/admin/categories_controller_spec.rb +++ b/spec/controllers/admin/categories_controller_spec.rb @@ -20,10 +20,16 @@ before(:each) do Category.new end + it "should render template new" do get :new assert_template 'new' end + + it "should redirect to new template" do + get :new + assert_response :success + end end describe "test_edit" do From 46089713dd80592aaf7b799b54cb19aa9228486b Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Tue, 29 Mar 2016 13:47:04 -0700 Subject: [PATCH 12/25] Edits made to categories controller spec and web steps suggested by Kari --- spec/controllers/admin/categories_controller_spec.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spec/controllers/admin/categories_controller_spec.rb b/spec/controllers/admin/categories_controller_spec.rb index 355319a231..e0f6061419 100644 --- a/spec/controllers/admin/categories_controller_spec.rb +++ b/spec/controllers/admin/categories_controller_spec.rb @@ -17,10 +17,6 @@ end describe "test_new" do - before(:each) do - Category.new - end - it "should render template new" do get :new assert_template 'new' From 074dd6c4e510eb57b2a83e80bf3592aa83dde902 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Wed, 30 Mar 2016 11:14:15 -0700 Subject: [PATCH 13/25] cucumber test for not admin --- features/merge_articles.feature | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 features/merge_articles.feature diff --git a/features/merge_articles.feature b/features/merge_articles.feature new file mode 100644 index 0000000000..4f886c6ca6 --- /dev/null +++ b/features/merge_articles.feature @@ -0,0 +1,13 @@ +Feature: Merge articles + As a blog administrator + In order to improve UX + I want to be able to merge my article with another similar article + + Background: + Given the blog is set up + And I am logged into the admin panel + And I am not an admin + + Scenario: Merge articles field is shown + Given I am on the article view page + When I follow "New Article" From 0545fd9d4f1c87ce322b9b91267b15b2ec4b2821 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Wed, 30 Mar 2016 11:30:42 -0700 Subject: [PATCH 14/25] cucumber test for not admin and on the new article page --- features/merge_articles.feature | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/features/merge_articles.feature b/features/merge_articles.feature index 4f886c6ca6..478074c0af 100644 --- a/features/merge_articles.feature +++ b/features/merge_articles.feature @@ -1,13 +1,13 @@ Feature: Merge articles As a blog administrator In order to improve UX - I want to be able to merge my article with another similar article + I want to be able to merge articles with other similar articles Background: Given the blog is set up And I am logged into the admin panel - And I am not an admin - Scenario: Merge articles field is shown - Given I am on the article view page + Scenario: Merge articles field is shown for admins only + Given I am on the new article page + And I am not an admin When I follow "New Article" From 2e9314edfb341c26cb9036e14cdd662136ec3069 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Wed, 30 Mar 2016 11:46:03 -0700 Subject: [PATCH 15/25] cucumber test that non admins should not see merge_with field --- features/merge_articles.feature | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/merge_articles.feature b/features/merge_articles.feature index 478074c0af..6151b4a136 100644 --- a/features/merge_articles.feature +++ b/features/merge_articles.feature @@ -8,6 +8,7 @@ Feature: Merge articles And I am logged into the admin panel Scenario: Merge articles field is shown for admins only - Given I am on the new article page + Given I am on the admin page And I am not an admin When I follow "New Article" + Then I should not see "merge_with" From 5094111aa96490c074e2cd9a9951cebf5096e043 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Wed, 30 Mar 2016 11:49:22 -0700 Subject: [PATCH 16/25] cucumber scenario passes when admin is logged in and cannot see merge_with --- features/merge_articles.feature | 8 +++++++- features/step_definitions/web_steps.rb | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/features/merge_articles.feature b/features/merge_articles.feature index 6151b4a136..b83dfb084b 100644 --- a/features/merge_articles.feature +++ b/features/merge_articles.feature @@ -7,8 +7,14 @@ Feature: Merge articles Given the blog is set up And I am logged into the admin panel - Scenario: Merge articles field is shown for admins only + Scenario: Merge articles field is not shown for non admins Given I am on the admin page And I am not an admin When I follow "New Article" Then I should not see "merge_with" + + Scenario: Merge articles field is shown for admins + Given I am on the admin page + And I am an admin + When I follow "New Article" + Then I should not see "merge_with" diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index f72b997bce..ebc2a058b8 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -55,6 +55,14 @@ def with_scope(locator) end end +And /^I am not an admin$/ do + User.name != 'admin' +end + +And /^I am an admin$/ do + User.name == 'admin' +end + # Single-line step scoper When /^(.*) within (.*[^:])$/ do |step, parent| with_scope(parent) { When step } @@ -163,7 +171,6 @@ def with_scope(locator) end Then /^I should have (\d+) new category$/ do |count| - # pending # express the regexp above with the code you wish you had # expect{Category.count}.to change{Category.count}.by(arg1) Category.count.should == count.to_i + 1 end From 6380488e589e264b874992fa3f0e31996f406ee6 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Wed, 30 Mar 2016 11:53:55 -0700 Subject: [PATCH 17/25] cucumber scenario for admin being able to see merge field, need to add merge_with to view --- features/merge_articles.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/merge_articles.feature b/features/merge_articles.feature index b83dfb084b..846d0acc90 100644 --- a/features/merge_articles.feature +++ b/features/merge_articles.feature @@ -17,4 +17,4 @@ Feature: Merge articles Given I am on the admin page And I am an admin When I follow "New Article" - Then I should not see "merge_with" + Then I should see "Merge Articles" From f5e254d808e43c1bd751a84ade640b7680f15b6b Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Wed, 30 Mar 2016 12:10:34 -0700 Subject: [PATCH 18/25] non admins are not allowed to edit - scenario passes --- features/merge_articles.feature | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/features/merge_articles.feature b/features/merge_articles.feature index 846d0acc90..ebe6a42d3e 100644 --- a/features/merge_articles.feature +++ b/features/merge_articles.feature @@ -8,13 +8,13 @@ Feature: Merge articles And I am logged into the admin panel Scenario: Merge articles field is not shown for non admins - Given I am on the admin page + Given I am on the admin content page And I am not an admin - When I follow "New Article" - Then I should not see "merge_with" + When I follow "Edit" + Then I should not see "Error, you are not allowed to perform this action" Scenario: Merge articles field is shown for admins - Given I am on the admin page + Given I am on the admin content page And I am an admin - When I follow "New Article" - Then I should see "Merge Articles" + When I follow "Edit" + Then I should see "merge_with" From edeef0c9b779471e78ac4619b023fb3257e34bce Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Wed, 30 Mar 2016 12:15:38 -0700 Subject: [PATCH 19/25] merge articles does not show on new article page - scenario passes --- features/merge_articles.feature | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/features/merge_articles.feature b/features/merge_articles.feature index ebe6a42d3e..2d9e51ab1d 100644 --- a/features/merge_articles.feature +++ b/features/merge_articles.feature @@ -7,6 +7,11 @@ Feature: Merge articles Given the blog is set up And I am logged into the admin panel + Scenario: Merge articles form is not shown on new article view + Given I am on the admin page + When I follow "New Article" + Then I should not see "Merge Articles" + Scenario: Merge articles field is not shown for non admins Given I am on the admin content page And I am not an admin @@ -17,4 +22,4 @@ Feature: Merge articles Given I am on the admin content page And I am an admin When I follow "Edit" - Then I should see "merge_with" + Then I should see "Merge Articles" From 7f5f30ee737bb0407ddf046199219623ef8da4d6 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Wed, 30 Mar 2016 12:18:16 -0700 Subject: [PATCH 20/25] scenarios written for seeing merge articles on edit article page as an admin --- features/merge_articles.feature | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/features/merge_articles.feature b/features/merge_articles.feature index 2d9e51ab1d..f2486ab4d3 100644 --- a/features/merge_articles.feature +++ b/features/merge_articles.feature @@ -12,6 +12,12 @@ Feature: Merge articles When I follow "New Article" Then I should not see "Merge Articles" + Scenario: Merge articles form is on edit article view + Given I am on the admin page + When I follow "All Articles" + And I follow "Edit" + Then I should see "Merge Articles" + Scenario: Merge articles field is not shown for non admins Given I am on the admin content page And I am not an admin From 2b634366cf9ec6163737dff46aa148fb7b4bb601 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Wed, 30 Mar 2016 12:19:14 -0700 Subject: [PATCH 21/25] remove scenario for merge articles on edit page as it was a duplicate --- features/merge_articles.feature | 6 ------ 1 file changed, 6 deletions(-) diff --git a/features/merge_articles.feature b/features/merge_articles.feature index f2486ab4d3..2d9e51ab1d 100644 --- a/features/merge_articles.feature +++ b/features/merge_articles.feature @@ -12,12 +12,6 @@ Feature: Merge articles When I follow "New Article" Then I should not see "Merge Articles" - Scenario: Merge articles form is on edit article view - Given I am on the admin page - When I follow "All Articles" - And I follow "Edit" - Then I should see "Merge Articles" - Scenario: Merge articles field is not shown for non admins Given I am on the admin content page And I am not an admin From 4dbe73d3894830554020806ff30015c059bc2ffd Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Wed, 30 Mar 2016 13:47:01 -0700 Subject: [PATCH 22/25] Test text that only shows when an admin user is logged in --- app/views/admin/content/_form.html.erb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/views/admin/content/_form.html.erb b/app/views/admin/content/_form.html.erb index 7b85db61c8..f62266fc38 100644 --- a/app/views/admin/content/_form.html.erb +++ b/app/views/admin/content/_form.html.erb @@ -16,7 +16,7 @@
<%= _("Status:") %> <%= @article.state.to_s.downcase %> Change
    -
@@ -146,8 +146,10 @@
    <%= render 'admin/content/attachment', { :attachment_num => 1, :hidden => false } -%>
-
+ + <% if current_user.admin? %> +

What?

+ <% end %> - From 0598dc2fefacf2eeb559d140bb2b8d9494369971 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Wed, 30 Mar 2016 15:09:37 -0700 Subject: [PATCH 23/25] scenarios that I thought were testing what I wanted tested are fixed - use with admin and not admin steps --- app/views/admin/content/_form.html.erb | 5 ++++- features/merge_articles.feature | 9 +++++---- features/step_definitions/web_steps.rb | 28 +++++++++++++++++++++----- features/support/paths.rb | 5 +++++ 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/app/views/admin/content/_form.html.erb b/app/views/admin/content/_form.html.erb index f62266fc38..2fd6ba7d3c 100644 --- a/app/views/admin/content/_form.html.erb +++ b/app/views/admin/content/_form.html.erb @@ -148,7 +148,10 @@ <% if current_user.admin? %> -

What?

+

Merge Articles

+ <% end %> diff --git a/features/merge_articles.feature b/features/merge_articles.feature index 2d9e51ab1d..7c3ed28b49 100644 --- a/features/merge_articles.feature +++ b/features/merge_articles.feature @@ -5,21 +5,22 @@ Feature: Merge articles Background: Given the blog is set up - And I am logged into the admin panel Scenario: Merge articles form is not shown on new article view Given I am on the admin page + And I am logged into the admin panel When I follow "New Article" Then I should not see "Merge Articles" Scenario: Merge articles field is not shown for non admins Given I am on the admin content page - And I am not an admin + And I am logged into the admin panel as a non admin When I follow "Edit" - Then I should not see "Error, you are not allowed to perform this action" + Then I should be on the admin content page + And I should see "Error, you are not allowed to perform this action" Scenario: Merge articles field is shown for admins Given I am on the admin content page - And I am an admin + And I am logged into the admin panel When I follow "Edit" Then I should see "Merge Articles" diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index ebc2a058b8..eaa8b4e69a 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -41,6 +41,12 @@ def with_scope(locator) :profile_id => 1, :name => 'admin', :state => 'active'}) + User.create!({:login => 'not admin', + :password => 'bbbbb', + :email => 'nojoe@snow.com', + :profile_id => 2, + :name => 'not admin', + :state => 'active'}) end And /^I am logged into the admin panel$/ do @@ -55,13 +61,25 @@ def with_scope(locator) end end -And /^I am not an admin$/ do - User.name != 'admin' +And /^I am logged into the admin panel as a non admin$/ do + visit '/accounts/login' + fill_in 'user_login', :with => 'not admin' + fill_in 'user_password', :with => 'bbbbb' + click_button 'Login' + if page.respond_to? :should + page.should have_content('Login successful') + else + assert page.has_content?('Login successful') + end end -And /^I am an admin$/ do - User.name == 'admin' -end +# And /^I am not an admin$/ do +# User.name != 'admin' +# end +# +# And /^I am an admin$/ do +# User.name == 'admin' +# end # Single-line step scoper When /^(.*) within (.*[^:])$/ do |step, parent| diff --git a/features/support/paths.rb b/features/support/paths.rb index 9c5eb20802..a464f35d53 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -21,6 +21,11 @@ def path_to(page_name) '/admin' when /^the category page$/ '/admin/categories/new' + when /^the admin content page$/ + '/admin/content' + when /^the admin edit content page$/ + '/admin/content/edit' + # Add more mappings here. # Here is an example that pulls values out of the Regexp: From deccf7ee3d0c11d6f38167522fe280bb0d0f6db4 Mon Sep 17 00:00:00 2001 From: Meighan Rasley Date: Wed, 30 Mar 2016 15:23:09 -0700 Subject: [PATCH 24/25] text 'Merge Articles' only shows up on edit view for admins only, all scenarios passing --- app/views/admin/content/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/content/_form.html.erb b/app/views/admin/content/_form.html.erb index 2fd6ba7d3c..f041eced52 100644 --- a/app/views/admin/content/_form.html.erb +++ b/app/views/admin/content/_form.html.erb @@ -147,7 +147,7 @@ <%= render 'admin/content/attachment', { :attachment_num => 1, :hidden => false } -%> - <% if current_user.admin? %> + <% if current_user.admin? && @article.title != nil %>

Merge Articles