Cucumber features for editing a keychain model - moralesalberto/personal GitHub Wiki
Feature: Editing of keychains
Background: A user logs into the application
Given a user is not logged in
And is a valid user with email "[email protected]" and password "working123"
When the user goes to the root page of the application
Then the user should be redirected to the login page
When the user enters his correct credentials in the login page, email: "[email protected]" and password "working123"
And submits the login page
Then the user should be shown the root page
Scenario: A user edits the name of a keychain record
Given an existing keychain with name "foo"
When the user goes to the edit keychain with the name "foo"
And fills in the name of the keychain to "bar"
And submits the keychain edit form
Then the keychain record should be updated with the name "bar"
Scenario: A user attempts to edits the name of a keychain record with the same name of another keychain
Given an existing keychain with name "first_one"
And another existing keychaing with the name "second_one"
When the user goes to the edit keychain with the name "second_one"
And fills in the name of the keychain to "first_one"
And submits the keychain edit form
Then the user should be shown an error "Name has already been taken"
And should be shown the edi
Step Definitions
When(/^the user goes to the new keychain page$/) do
visit(new_keychain_path)
end
When(/^fills in the keychain name: "(.*?)"$/) do |keychain_name|
fill_in('keychain_name', :with => keychain_name)
end
When(/^username: "(.*?)"$/) do |username|
fill_in('keychain_username', :with => username)
end
When(/^password: "(.*?)"$/) do |password|
fill_in('keychain_password', :with => password)
end
When(/^description: "(.*?)"$/) do |description|
fill_in('keychain_description', :with => description)
end
When(/^submits the new keychain form$/) do
click_on('Save keychain')
end
Then(/^a new keychain record is created with the name "(.*?)", and password: "(.*?)"$/) do |name, password|
keychains = Keychain.where('name = ?', name)
keychains.size.should eq(1)
keychains.first.password_encrypted.should_not eq(password)
keychains.first.password.should eq(password)
end
Then(/^the admin is emailed that the keychain "(.*?)" was shown to a user$/) do |name|
emails = ActionMailer::Base.deliveries.select {|email| email.subject =~ /#{name}/}
emails.size.should eq(1)
emails.first.to.first.should eq('[email protected]')
end