Created
September 26, 2011 14:52
-
-
Save haad/1242411 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # :class => points to name of model used. | |
| # | |
| FactoryGirl.define do | |
| # User groups | |
| factory :role_group, :class => :RoleGroup do | |
| name 'client' | |
| end | |
| # Define basic Role object | |
| factory :role, :class => :Role do | |
| name 'admin' | |
| weight '0' | |
| group RoleGroup.find_by_name('client') | |
| end | |
| # Define Person object | |
| factory :person, :class => :Person do | |
| email '[email protected]' | |
| end | |
| factory :country, :class => :Country do | |
| name 'Slovakia' | |
| code 'SK' | |
| end | |
| # Create actual user types | |
| factory :admin, :class => :User do |u| | |
| u.password '123' | |
| u.password_confirmation '123' | |
| u.aasm_state :active | |
| u.role Role.find_by_name("admin") | |
| u.person {|person| person.association(:person, :email => "[email protected]")} | |
| u.after_build {|user| | |
| user.countries << Country.all | |
| } | |
| end | |
| factory :central, :class => :User do |u| | |
| u.password '123' | |
| u.password_confirmation '123' | |
| u.aasm_state :active | |
| u.role Role.find_by_name("central") | |
| u.person {|person| person.association(:person, :email => "[email protected]")} | |
| end | |
| factory :tmm, :class => :User do |u| | |
| u.password '123' | |
| u.password_confirmation '123' | |
| u.aasm_state :active | |
| u.role Role.find_by_name("tmm") | |
| u.person {|person| person.association(:person, :email => "[email protected]")} | |
| end | |
| factory :kam, :class => :User do |u| | |
| u.password '123' | |
| u.password_confirmation '123' | |
| u.aasm_state :active | |
| u.role Role.find_by_name("kam") | |
| u.person {|person| person.association(:person, :email => "[email protected]")} | |
| end | |
| factory :ip, :class => :User do |u| | |
| u.password '123' | |
| u.password_confirmation '123' | |
| u.aasm_state :active | |
| u.role Role.find_by_name("ip") | |
| u.person {|person| person.association(:person, :email => "[email protected]")} | |
| end | |
| end | |
| Given /^I am not authenticated$/ do | |
| visit('/logout') # ensure that at least | |
| end | |
| Given /^the following role groups exists:$/ do |table| | |
| puts hash["name"].to_s | |
| table.hashes.each do |hash| | |
| FactoryGirl.create(:role_group, :name => hash["name"]) | |
| end | |
| end | |
| Given /^the following roles exists:$/ do |table| | |
| table.hashes.each do |hash| | |
| role = FactoryGirl.create(:role, :name => hash["name"], :weight => hash["weight"], :group => RoleGroup.find_by_name(hash["group"])) | |
| hash["allowed_roles"].split(",").each {|allowed_role| | |
| role.allowed_roles.find_or_create_by_role_ref_id(allowed_role) | |
| } | |
| end | |
| end | |
| Given /^the following countries exists:$/ do |table| | |
| table.hashes.each do |hash| | |
| FactoryGirl.create(:country, :name => hash["name"], :code => hash["code"]) | |
| end | |
| end | |
| Given /^the following users exists:$/ do |table| | |
| table.hashes.each do |hash| | |
| person = Person.find_by_email(hash["email"]) | |
| if !person | |
| FactoryGirl.create(hash["role"].to_sym) | |
| end | |
| end | |
| end | |
| Given /^Sign in user with email "([^\"]*)" and password "([^\"]*)" to site$/ do |email, password| | |
| Then %{I go to login} | |
| And %{I should see "Login"} | |
| And %{I fill in "Email" with "#{email}"} | |
| And %{I fill in "Password" with "#{password}"} | |
| And %{I press "Confirm"} | |
| end | |
| @login | |
| Feature: Login to site | |
| To test if User Authentication works as expected we try to login with created | |
| user name/password and check if we can see expected Logout text in Shop Listings site. | |
| We try to login different types of users to see if it works. | |
| Background: | |
| Given the following role groups exists: | |
| |name| | |
| |client| | |
| |producer| | |
| Given the following roles exists: | |
| |name|weight|group|allowed_roles| | |
| |ip|3|producer|| | |
| |kam|3|client|| | |
| |tmm|2|client|tmm,kam| | |
| |central|1|client|central,tmm| | |
| |admin|0|client|admin,central,tmm,kam,ip| | |
| Given the following countries exists: | |
| |name|code| | |
| |Slovakia|SK| | |
| |Czech Republic|CZ| | |
| |Austria|AU| | |
| |Hungary|HU| | |
| Given the following users exists: | |
| |email|password|role|countries| | |
| |[email protected]|123|admin|SK,CZ,AU,HU| | |
| |[email protected]|123|central|SK,CZ,AU| | |
| |[email protected]|123|tmm|SK,CZ| | |
| |[email protected]|123|kam|SK| | |
| |[email protected]|123|ip|| | |
| Scenario Outline: Successful Login | |
| Given I am not authenticated | |
| When I am on the new login page | |
| Then I should see "Login" | |
| And I fill in "Email" with "<email>" | |
| And I fill in "Password" with "<password>" | |
| And I press "Confirm" | |
| Then I should see "Logout" | |
| When I go to "logout" | |
| Then I should see "Login" | |
| Examples: | |
| |email|password| | |
| |[email protected]|123| | |
| |[email protected]|123| | |
| |[email protected]|123| | |
| |[email protected]|123| | |
| |[email protected]|123| | |
| Scenario: Failed Login | |
| Given I am not authenticated | |
| Given the following users exists: | |
| |email|password|role| | |
| |[email protected]|123|admin| | |
| When I am on the new login page | |
| Then I should see "Login" | |
| And I fill in "Email" with "[email protected]" | |
| And I fill in "Password" with "123" | |
| And I press "Confirm" | |
| Then I should see "Invalid email or password" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment