From 48f869dc27e1dd19b842857a16a66de13b236d7a Mon Sep 17 00:00:00 2001 From: "M. Scott Ford" Date: Fri, 12 Aug 2011 22:56:48 -0400 Subject: [PATCH 1/3] Added failing feature for to illustrate issue with has_many relationships. --- features/admin/content_types/has_many.feature | 51 +++++++++++++++++++ features/support/selectors.rb | 8 ++- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 features/admin/content_types/has_many.feature diff --git a/features/admin/content_types/has_many.feature b/features/admin/content_types/has_many.feature new file mode 100644 index 00000000..f402373d --- /dev/null +++ b/features/admin/content_types/has_many.feature @@ -0,0 +1,51 @@ +Feature: Create and manage has many relationships + In order to work with two associated models together + As an administrator + I want to set up and manage a has many relationship + +Background: + Given I have the site: "test site" set up + And I have a custom model named "Projects" with + | label | kind | required | target | + | Name | string | true | | + | Description | text | false | | + And I have a custom model named "Clients" with + | label | kind | required | target | + | Name | string | true | | + | Description | string | false | | + | Projects | has_many | false | Projects | + And I have entries for "Clients" with + | name | description | + | Alpha, Inc | Description for Alpha, Inc | + | Beta, Inc | Description for Beta, Inc | + | Gamma, Inc | Description for Gamma, Inc | + And I have entries for "Projects" with + | name | description | + | Fun project | Description for the fun one | + | Boring project | Description for the boring one | + + And I am an authenticated user + +@javascript +Scenario: I view a client without any projects + When I go to the "Clients" model list page + And I follow "Alpha, Inc" + And I wait until ".has-many-selector" is visible + Then I should see "Empty" within the list of items + +@javascript +Scenario: I add a project to a client + When I go to the "Clients" model list page + And I follow "Beta, Inc" + And I wait until ".has-many-selector ul li.template" is visible + Then "Fun project" should be an option for "label" + And I press "+ add" + When I press "Save" + And I wait until ".has-many-selector ul li.template" is visible + Then I should see "Fun project" within the list of added items + And I should not see "Empty" within the list of items + When I go to the "Clients" model list page + And I follow "Beta, Inc" + And I wait until ".has-many-selector ul li.template" is visible + Then I should see "Fun project" within the list of added items + And I should not see "Empty" within the list of items diff --git a/features/support/selectors.rb b/features/support/selectors.rb index d1ae28c5..b57c196c 100644 --- a/features/support/selectors.rb +++ b/features/support/selectors.rb @@ -13,7 +13,13 @@ module HtmlSelectorsHelpers when "the main form" "form.formtastic" - + + when "the list of added items" + ".has-many-selector li.item.added" + + when "the list of items" + ".has-many-selector" + # Add more mappings here. # Here is an example that pulls values out of the Regexp: # From 1d85c0dbf3791fa125e303c418b74d08ef32e63c Mon Sep 17 00:00:00 2001 From: "M. Scott Ford" Date: Fri, 12 Aug 2011 23:21:27 -0400 Subject: [PATCH 2/3] Cleaned up the use of the 'wait until' steps in the has many examples. --- features/admin/content_types/has_many.feature | 8 ++++---- features/admin/content_types/has_many_reverse.feature | 8 ++++---- features/step_definitions/more_web_steps.rb | 4 ++++ features/step_definitions/within_steps.rb | 1 - features/support/selectors.rb | 3 +++ 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/features/admin/content_types/has_many.feature b/features/admin/content_types/has_many.feature index f402373d..e8776a64 100644 --- a/features/admin/content_types/has_many.feature +++ b/features/admin/content_types/has_many.feature @@ -30,22 +30,22 @@ Background: Scenario: I view a client without any projects When I go to the "Clients" model list page And I follow "Alpha, Inc" - And I wait until ".has-many-selector" is visible + And I wait until the has many selector is visible Then I should see "Empty" within the list of items @javascript Scenario: I add a project to a client When I go to the "Clients" model list page And I follow "Beta, Inc" - And I wait until ".has-many-selector ul li.template" is visible + And I wait until the has many selector is visible Then "Fun project" should be an option for "label" And I press "+ add" When I press "Save" - And I wait until ".has-many-selector ul li.template" is visible + And I wait until the has many selector is visible Then I should see "Fun project" within the list of added items And I should not see "Empty" within the list of items When I go to the "Clients" model list page And I follow "Beta, Inc" - And I wait until ".has-many-selector ul li.template" is visible + And I wait until the has many selector is visible Then I should see "Fun project" within the list of added items And I should not see "Empty" within the list of items diff --git a/features/admin/content_types/has_many_reverse.feature b/features/admin/content_types/has_many_reverse.feature index edf6db67..5850752c 100644 --- a/features/admin/content_types/has_many_reverse.feature +++ b/features/admin/content_types/has_many_reverse.feature @@ -36,26 +36,26 @@ Scenario: I do not see the "Add Item" button for new parent Scenario: I attach already created items for an existing parent and save it When I go to the "Clients" model list page And I follow "Apple Inc" - And I wait until ".has-many-selector ul li.template" is visible + And I wait until the has many selector is visible Then "My sexy project" should be an option for "label" When I select "My sexy project" from "label" And I press "+ add" And "My sexy project" should not be an option for "label" When I press "Save" - And I wait until ".has-many-selector ul li.template" is visible + And I wait until the has many selector is visible Then "My sexy project" should not be an option for "label" @javascript Scenario: I create a new item and attach it When I go to the "Clients" model list page And I follow "Apple Inc" - And I wait until ".has-many-selector ul li.template" is visible + And I wait until the has many selector is visible And I press "+ add" Then I should see "Apple Inc » Projects — new item" And I should not see "Client" within the main form When I fill in "Name" with "iPad" And I press "Create" Then I should see "Content was successfully created." - When I wait until ".has-many-selector ul li.template" is visible + When I wait until the has many selector is visible Then I should see "iPad" And "iPad" should not be an option for "label" diff --git a/features/step_definitions/more_web_steps.rb b/features/step_definitions/more_web_steps.rb index 9ded333e..28c9e15c 100644 --- a/features/step_definitions/more_web_steps.rb +++ b/features/step_definitions/more_web_steps.rb @@ -10,6 +10,10 @@ When /^I wait until "([^"]*)" is visible$/ do |selector| page.has_css?("#{selector}", :visible => true) end +When /^I wait until ([^"]*) is visible$/ do |locator| + page.has_css?(selector_for(locator), :visible => true) +end + Then /^"([^"]*)" should( not)? be an option for "([^"]*)"(?: within "([^\"]*)")?$/ do |value, negate, field, selector| with_scope(selector) do expectation = negate ? :should_not : :should diff --git a/features/step_definitions/within_steps.rb b/features/step_definitions/within_steps.rb index 4b6b66f5..7131e694 100644 --- a/features/step_definitions/within_steps.rb +++ b/features/step_definitions/within_steps.rb @@ -1,7 +1,6 @@ # http://mislav.uniqpath.com/2010/09/cuking-it-right/ { - # 'as a movie title in the results' => 'ol.movies h1', # 'in a button' => 'button, input[type=submit]', # 'in the navigation' => 'nav' diff --git a/features/support/selectors.rb b/features/support/selectors.rb index b57c196c..32339920 100644 --- a/features/support/selectors.rb +++ b/features/support/selectors.rb @@ -19,6 +19,9 @@ module HtmlSelectorsHelpers when "the list of items" ".has-many-selector" + + when "the has many selector" + ".has-many-selector ul li.template" # Add more mappings here. # Here is an example that pulls values out of the Regexp: From 19f4fe295d032476ecfc4b1a5727b0a432e61f24 Mon Sep 17 00:00:00 2001 From: "M. Scott Ford" Date: Fri, 12 Aug 2011 23:51:34 -0400 Subject: [PATCH 3/3] Illustrated that the reverse has many feature is also having the same problem. --- features/admin/content_types/has_many_reverse.feature | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/features/admin/content_types/has_many_reverse.feature b/features/admin/content_types/has_many_reverse.feature index 5850752c..a0f01c04 100644 --- a/features/admin/content_types/has_many_reverse.feature +++ b/features/admin/content_types/has_many_reverse.feature @@ -44,6 +44,12 @@ Scenario: I attach already created items for an existing parent and save it When I press "Save" And I wait until the has many selector is visible Then "My sexy project" should not be an option for "label" + When I go to the "Clients" model list page + And I follow "Apple Inc" + And I wait until the has many selector is visible + Then "My sexy project" should not be an option for "label" + And I should not see "Empty" within the list of items + @javascript Scenario: I create a new item and attach it @@ -59,3 +65,8 @@ Scenario: I create a new item and attach it When I wait until the has many selector is visible Then I should see "iPad" And "iPad" should not be an option for "label" + When I go to the "Clients" model list page + And I follow "Apple Inc" + And I wait until the has many selector is visible + Then "iPad" should not be an option for "label" + And I should not see "Empty" within the list of items