Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Commit

Permalink
Change all instances of user into account
Browse files Browse the repository at this point in the history
  • Loading branch information
cilim committed Aug 25, 2016
1 parent a325925 commit ef30e73
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 84 deletions.
2 changes: 1 addition & 1 deletion spec/factories.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FactoryGirl.define do
factory :account, class: Stormpath::Resource::Account do
sequence(:email) { |n| "dev-#{n}@infinum.co" }
sequence(:email) { |n| "dev#{n}@example.com" }
password 'Password1337'
given_name { Faker::Name.first_name }
surname { Faker::Name.last_name }
Expand Down
6 changes: 3 additions & 3 deletions spec/features/access_usage_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

describe 'POST /login' do
describe 'proper email and password' do
let(:user) { create_test_account }
let(:account) { create_test_account }

after { delete_test_account }

it 'has access to his profile if signed in' do
visit 'login'
fill_in 'Username or Email', with: user.email
fill_in 'Username or Email', with: account.email
fill_in 'Password', with: 'Password1337'
click_button 'Log in'
expect(page).to have_content 'Root page'
visit 'my_profile'
expect(page).to have_content user.email
expect(page).to have_content account.email
end

it "doesn't have access to his profile if not signed in" do
Expand Down
8 changes: 4 additions & 4 deletions spec/features/login_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,21 @@
end

describe 'proper email and password' do
let(:user) { create_test_account }
let(:account) { create_test_account }

after { delete_test_account }

it 'redirects to root page' do
visit 'login'
fill_in 'Username or Email', with: user.email
fill_in 'Username or Email', with: account.email
fill_in 'Password', with: 'Password1337'
click_button 'Log in'
expect(page).to have_content 'Root page'
end

it 'sets cookies' do
visit 'login'
fill_in 'Username or Email', with: user.email
fill_in 'Username or Email', with: account.email
fill_in 'Password', with: 'Password1337'
click_button 'Log in'
expect(page.driver.request.cookies['access_token']).to be
Expand All @@ -157,7 +157,7 @@
allow(login_config).to receive(:next_uri).and_return('/about')

visit 'login'
fill_in 'Username or Email', with: user.email
fill_in 'Username or Email', with: account.email
fill_in 'Password', with: 'Password1337'
click_button 'Log in'
expect(page).to have_content 'About us'
Expand Down
20 changes: 6 additions & 14 deletions spec/requests/forgot_password/post_spec.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
require 'spec_helper'

describe 'ForgotPassword POST', type: :request, vcr: true do
let(:user) { Stormpath::Rails::Client.application.accounts.create(user_attrs) }

let(:user_attrs) do
{
email: 'example@test.com',
given_name: 'Example',
surname: 'Test',
password: 'Pa$$W0RD',
username: 'SirExample'
}
end
let(:account) { Stormpath::Rails::Client.application.accounts.create(account_attrs) }

let(:account_attrs) { FactoryGirl.attributes_for(:account) }

before do
user
account
enable_forgot_password
Rails.application.reload_routes!
end

after { user.delete }
after { account.delete }

context 'application/json' do
def json_forgot_post(attrs = {})
Expand All @@ -28,7 +20,7 @@ def json_forgot_post(attrs = {})

context 'valid data' do
it 'return 200 OK' do
json_forgot_post(email: user.email)
json_forgot_post(email: account.email)
expect(response).to be_success
end
end
Expand Down
74 changes: 33 additions & 41 deletions spec/requests/login/post_spec.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
require 'spec_helper'

describe 'Login POST', type: :request, vcr: true do
let(:user) { Stormpath::Rails::Client.application.accounts.create(user_attrs) }

let(:user_attrs) do
{
email: 'example@test.com',
given_name: 'Example',
surname: 'Test',
password: 'Pa$$W0RD',
username: 'SirExample'
}
end
let(:account) { Stormpath::Rails::Client.application.accounts.create(account_attrs) }

let(:account_attrs) { FactoryGirl.attributes_for(:account) }

before { user }
before { account }

before do
Rails.application.reload_routes!
end

after { user.delete }
after { account.delete }

describe 'HTTP_ACCEPT=text/html' do
describe 'html is enabled' do
it 'successfull login' do
post '/login', login: user_attrs[:email], password: user_attrs[:password]
post '/login', login: account_attrs[:email], password: account_attrs[:password]
expect(response).to redirect_to('/')
expect(response.status).to eq(302)
end

it 'failed login, wrong password' do
post '/login', login: user_attrs[:email], password: 'WR00N6'
post '/login', login: account_attrs[:email], password: 'WR00N6'
expect(response.status).to eq(200)
expect(response.body).to include('Invalid username or password')
end
Expand All @@ -43,7 +35,7 @@
end

it 'returns 404' do
post '/login', login: user_attrs[:email], password: user_attrs[:password]
post '/login', login: account_attrs[:email], password: account_attrs[:password]
expect(response.status).to eq(404)
end
end
Expand All @@ -56,58 +48,58 @@ def json_login_post(attrs)

describe 'json is enabled' do
it 'successfull login should result with 200' do
json_login_post(login: user_attrs[:email], password: user_attrs[:password])
json_login_post(login: account_attrs[:email], password: account_attrs[:password])
expect(response.status).to eq(200)
end

it 'successfull login with username should result with 200' do
json_login_post(login: user_attrs[:username], password: user_attrs[:password])
json_login_post(login: account_attrs[:username], password: account_attrs[:password])
expect(response.status).to eq(200)
end

it 'successfull login should have content-type application/json' do
json_login_post(login: user_attrs[:email], password: user_attrs[:password])
json_login_post(login: account_attrs[:email], password: account_attrs[:password])
expect(response.content_type.to_s).to eq('application/json')
end

it 'successfull login should match schema' do
json_login_post(login: user_attrs[:email], password: user_attrs[:password])
json_login_post(login: account_attrs[:email], password: account_attrs[:password])
expect(response).to match_response_schema(:login_response, strict: true)
end

it 'successfull login should set cookies' do
json_login_post(login: user_attrs[:email], password: user_attrs[:password])
json_login_post(login: account_attrs[:email], password: account_attrs[:password])
expect(response.cookies['access_token']).to be
expect(response.cookies['refresh_token']).to be
end

it 'successful login should match json' do
json_login_post(login: user_attrs[:email], password: user_attrs[:password])
json_login_post(login: account_attrs[:email], password: account_attrs[:password])
expect(response).to match_json <<-JSON
{
"account":{
"href":"{string}",
"username":"SirExample",
"username":"#{account.username}",
"modifiedAt":"{date_time_iso8601}",
"status":"ENABLED",
"createdAt":"{date_time_iso8601}",
"email":"example@test.com",
"email":"#{account.email}",
"middleName":null,
"surname":"Test",
"givenName":"Example",
"fullName":"Example Test"
"surname":"#{account.surname}",
"givenName":"#{account.given_name}",
"fullName":"#{account.given_name} #{account.surname}"
}
}
JSON
end

it 'failed login, wrong password should result with 400' do
json_login_post(login: user_attrs[:email], password: 'WR00N6')
json_login_post(login: account_attrs[:email], password: 'WR00N6')
expect(response.status).to eq(400)
end

it 'failed login, wrong password should result with a message in the response body' do
json_login_post(login: user_attrs[:email], password: 'WR00N6')
json_login_post(login: account_attrs[:email], password: 'WR00N6')

response_body = JSON.parse(response.body)
expect(response_body['status']).to eq(400)
Expand All @@ -122,7 +114,7 @@ def json_login_post(attrs)
end

it 'returns 404' do
json_login_post(login: user_attrs[:email], password: user_attrs[:password])
json_login_post(login: account_attrs[:email], password: account_attrs[:password])
expect(response.status).to eq(404)
end
end
Expand All @@ -135,35 +127,35 @@ def login_post_with_nil_http_accept(attrs)

describe 'json is enabled' do
it 'successfull login should result with 200' do
login_post_with_nil_http_accept(login: user_attrs[:email], password: user_attrs[:password])
login_post_with_nil_http_accept(login: account_attrs[:email], password: account_attrs[:password])
expect(response.status).to eq(200)
end

it 'successfull login with username should result with 200' do
login_post_with_nil_http_accept(
login: user_attrs[:username],
password: user_attrs[:password]
login: account_attrs[:username],
password: account_attrs[:password]
)
expect(response.status).to eq(200)
end

it 'successfull login should have content-type application/json' do
login_post_with_nil_http_accept(login: user_attrs[:email], password: user_attrs[:password])
login_post_with_nil_http_accept(login: account_attrs[:email], password: account_attrs[:password])
expect(response.content_type.to_s).to eq('application/json')
end

it 'successfull login should match schema' do
login_post_with_nil_http_accept(login: user_attrs[:email], password: user_attrs[:password])
login_post_with_nil_http_accept(login: account_attrs[:email], password: account_attrs[:password])
expect(response).to match_response_schema(:login_response, strict: true)
end

it 'failed login, wrong password should result with 400' do
login_post_with_nil_http_accept(login: user_attrs[:email], password: 'WR00N6')
login_post_with_nil_http_accept(login: account_attrs[:email], password: 'WR00N6')
expect(response.status).to eq(400)
end

it 'failed login, wrong password should result with a message in the response body' do
login_post_with_nil_http_accept(login: user_attrs[:email], password: 'WR00N6')
login_post_with_nil_http_accept(login: account_attrs[:email], password: 'WR00N6')

response_body = JSON.parse(response.body)
expect(response_body['status']).to eq(400)
Expand All @@ -178,7 +170,7 @@ def login_post_with_nil_http_accept(attrs)
end

it 'returns 404' do
login_post_with_nil_http_accept(login: user_attrs[:email], password: user_attrs[:password])
login_post_with_nil_http_accept(login: account_attrs[:email], password: account_attrs[:password])
expect(response.status).to eq(302)
end
end
Expand All @@ -191,7 +183,7 @@ def login_post_with_nil_http_accept(attrs)
end

it 'returns 404' do
post '/login', login: user_attrs[:email], password: user_attrs[:password]
post '/login', login: account_attrs[:email], password: account_attrs[:password]
expect(response.status).to eq(404)
end
end
Expand All @@ -200,15 +192,15 @@ def login_post_with_nil_http_accept(attrs)
before { allow(configuration.web.login).to receive(:next_uri).and_return('/abc') }

it 'should redirect to next_uri' do
post '/login', login: user_attrs[:email], password: user_attrs[:password]
post '/login', login: account_attrs[:email], password: account_attrs[:password]
expect(response).to redirect_to('/abc')
expect(response.status).to eq(302)
end
end

describe 'login sent with ?next=other_url' do
it 'should redirect to next_uri' do
post '/login?next=/other', login: user_attrs[:email], password: user_attrs[:password]
post '/login?next=/other', login: account_attrs[:email], password: account_attrs[:password]
expect(response).to redirect_to('/other')
expect(response.status).to eq(302)
end
Expand Down

0 comments on commit ef30e73

Please sign in to comment.