On 05/03/2012 02:11 PM, Jason Guiditta wrote:
https://www.aeolusproject.org/redmine/issues/3211
DMA means 'Direct Model Access'. The basic idea is that your test
should only be testing the part of the app that the test is directly
intended for. A good example (and the subject of this patch/feature)
is login. The actual steps of logging in shoudl be tested in one place
only. All other cases where the user is expected to be logged in should
avoid duplicating this set of steps, and instead assume that we have a
valid, logged in user to work with.
This concept is decribed in more detail on the wiki[1], as well as providing
a place for questions and common problems to be explained as they come up.
[1]
https://www.aeolusproject.org/redmine/projects/aeolus/wiki/Testing_DMA
---
src/features/authentication.feature | 8 +++++---
src/features/pool_family.feature | 3 ++-
src/features/step_definitions/authentication.rb | 13 ++++++++++++-
src/features/step_definitions/pool_steps.rb | 5 -----
src/features/support/custom.rb | 2 ++
src/features/support/paths.rb | 2 +-
6 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/src/features/authentication.feature b/src/features/authentication.feature
index 4a2ce82..98c130c 100644
--- a/src/features/authentication.feature
+++ b/src/features/authentication.feature
@@ -17,7 +17,7 @@ Feature: User authentication
And I should be on the login error page
Scenario: Edit profile
- Given I am logged in
+ Given I have successfully logged in
And I am on the root page
When I want to edit my profile
Then should see "Edit Account"
@@ -27,7 +27,8 @@ Feature: User authentication
And I should see "User updated!"
Scenario: log out
- Given I am logged in
+ Given I am an authorised user
Could this have been "Given I am a
registered user"?
It works either way, but wondering if there is a specific reason to use
the admin user.
+ And I am logged in
And I am on the root page
When I follow "Log out"
Then I should see "Username:"
@@ -35,7 +36,8 @@ Feature: User authentication
And I should see "Show my password"
Scenario: Change user login to one with invalid length
- Given I am logged in
+ Given I am a registered user
+ And I am logged in
And I am on the root page
When I want to edit my profile
Then should see "Edit Account"
diff --git a/src/features/pool_family.feature b/src/features/pool_family.feature
index 2c635dd..4078867 100644
--- a/src/features/pool_family.feature
+++ b/src/features/pool_family.feature
@@ -22,7 +22,8 @@ Feature: Pool Families
| pool_family3 |
Scenario: List pool families as unprivileged user
- Given I am logged in
+ Given I am a registered user
+ And I am logged in
And there is a pool family named "hiddenpoolfamily"
And I can view pool family "testpoolfamily"
When I go to the pool families page
diff --git a/src/features/step_definitions/authentication.rb
b/src/features/step_definitions/authentication.rb
index bde0975..467720a 100644
--- a/src/features/step_definitions/authentication.rb
+++ b/src/features/step_definitions/authentication.rb
@@ -18,7 +18,7 @@ def user
end
def admin_user
- @user ||= FactoryGirl.create :admin_user
+ user ||= FactoryGirl.create :admin_user
end
def login(login, password)
@@ -44,6 +44,12 @@ Given /^I am a registered user$/ do
user
end
+Given /^I am an authorised user$/ do
+ @admin_permission = FactoryGirl.create :admin_permission
+ @user = @admin_permission.user
+end
+
+
When /^I login$/ do
login(user.login, user.password)
end
@@ -59,6 +65,11 @@ Given /^I am a new user$/ do
end
Given /^I am logged in$/ do
+ # Warden test helper method
+ login_as user
+end
+
+Given /^I have successfully logged in$/ do
page.driver.header 'Accept-Language', 'en-US'
login(user.login, user.password)
page.should have_content('Login successful!')
diff --git a/src/features/step_definitions/pool_steps.rb
b/src/features/step_definitions/pool_steps.rb
index 3f0c050..8e73121 100644
--- a/src/features/step_definitions/pool_steps.rb
+++ b/src/features/step_definitions/pool_steps.rb
@@ -13,11 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-Given /^I am an authorised user$/ do
- @admin_permission = FactoryGirl.create :admin_permission
- @user = @admin_permission.user
-end
-
Given /^I have Pool Creator permissions on a pool named "([^\"]*)"$/ do
|name|
@pool = FactoryGirl.create(:pool, :name => name)
FactoryGirl.create(:pool_creator_permission, :user => @user, :permission_object
=> @pool)
diff --git a/src/features/support/custom.rb b/src/features/support/custom.rb
index e529073..02a60a4 100644
--- a/src/features/support/custom.rb
+++ b/src/features/support/custom.rb
@@ -15,6 +15,8 @@
#
#Seed the DB with fixture data
+include Warden::Test::Helpers
+Warden.test_mode!
# We can't stub out these methods properly in cucumber, and we don't want to
# couple these tests to require the core server be running (connections should be
tested
# in the client code), so override the methods for tests here.
diff --git a/src/features/support/paths.rb b/src/features/support/paths.rb
index 3a7796e..38f926d 100644
--- a/src/features/support/paths.rb
+++ b/src/features/support/paths.rb
@@ -174,7 +174,7 @@ module NavigationHelpers
pool_path(pool, :view => 'filter')
when /^the my user page$/
- user_path(user) #(User.find_by_login($1))
+ user_path(user)
when /^the (.*)'s edit user page$/
edit_user_path(User.find_by_login($1))
Nice writeup on DMA and on a way to speed up to our tests.