Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Admin scenarios

  • Loading branch information...
commit a6801ddc61143791a70861c834ae812efc34a4de 1 parent 17722b5
Andy Waite authored
View
19 features/admin.feature
@@ -0,0 +1,19 @@
+Feature: Admin
+
+ Scenario: Attempt to access admin area
+
+ When I visit the seller admin
+ Then I should be prompted to sign in
+
+ @user
+ Scenario: login with valid credentials
+
+ When I visit the seller admin
+ And I login with valid credentials
+ Then I should be welcomed
+
+ Scenario: Attempt to login with invalid credentials
+
+ When I visit the seller admin
+ And I login with invalid credentials
+ Then I should be denied access
View
29 features/step_definitions/admin_steps.rb
@@ -0,0 +1,29 @@
+Then /^I should be prompted to sign in$/ do
+ @page.should have_login_form
+end
+
+When /^I visit the seller admin$/ do
+ @page = Pages::Admin::Index.new
+ @page.visit
+end
+
+When /^I login with valid credentials$/ do
+ user = FactoryGirl.create(:user)
+ @page = Pages::Admin::Index.new
+ @page.visit
+ @page.sign_in user.name, user.password
+end
+
+Then /^I should be welcomed$/ do
+ @page.welcomed?.should be_true
+end
+
+When /^I login with invalid credentials$/ do
+ user = FactoryGirl.create(:user)
+ @page = Pages::Admin::Index.new
+ @page.sign_in user.name, 'invalid'
+end
+
+Then /^I should be denied access$/ do
+ @page.denied_access?.should be_true
+end
View
1  features/support/component/checkout_form.rb
@@ -1,6 +1,7 @@
module Component
class CheckoutForm < CapybaraPageObject::Form
# TODO how to avoid needing source here?
+ # TODO shouldn't copybara page object handle this?
def name=(name)
source.fill_in 'Name', :with => name
end
View
9 features/support/component/login_form.rb
@@ -0,0 +1,9 @@
+module Component
+ class LoginForm < CapybaraPageObject::Form
+ def sign_in(name, password)
+ source.fill_in 'Name', :with => name
+ source.fill_in 'Password', :with => password
+ source.click_button 'Login'
+ end
+ end
+end
View
7 features/support/factories.rb
@@ -8,3 +8,10 @@
price 9.99
end
end
+
+FactoryGirl.define do
+ factory :user do
+ name 'admin'
+ password 'password'
+ end
+end
View
31 features/support/pages/admin/index.rb
@@ -0,0 +1,31 @@
+require_relative '../base' # TODO why is this needed?
+
+module Pages
+ module Admin
+ class Index < Pages::Base
+ def login_form
+ Component::LoginForm.new(find('.depot_form'))
+ end
+
+ def has_login_form?
+ has_content?('Please Log In')
+ end
+
+ def path
+ '/admin'
+ end
+
+ def sign_in(*args)
+ login_form.sign_in(*args)
+ end
+
+ def welcomed?
+ has_content?('Welcome')
+ end
+
+ def denied_access?
+ notice == 'Invalid user/password combination'
+ end
+ end
+ end
+end
View
5 features/support/pages/base.rb
@@ -1,5 +1,6 @@
module Pages
class Base < CapybaraPageObject::Node
+
def cart
Component::Cart.new find('#cart')
end
@@ -11,5 +12,9 @@ def checkout_available?
def errors
all('#error_explanation ul li').collect(&:text)
end
+
+ def notice
+ find('#notice').text
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.