2014-08-30 17:38:47 +00:00
|
|
|
require 'rails_helper'
|
2012-03-04 22:07:45 +00:00
|
|
|
|
|
|
|
describe UsersController do
|
|
|
|
|
2012-04-09 21:53:38 +00:00
|
|
|
describe '#show' do
|
2014-02-12 19:51:01 +00:00
|
|
|
subject { get :show, username: username }
|
2014-02-12 18:51:25 +00:00
|
|
|
|
2014-02-12 19:51:01 +00:00
|
|
|
let(:username) { user.username }
|
2014-02-12 18:51:25 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
2014-10-05 16:25:49 +00:00
|
|
|
context "when confirmed user username given" do
|
2014-02-12 18:51:25 +00:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2014-03-16 17:34:37 +00:00
|
|
|
it 'renders "show" template' do
|
2014-02-12 18:51:25 +00:00
|
|
|
should render_template('show')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-10-05 16:25:49 +00:00
|
|
|
context "when unconfirmed user username given" do
|
|
|
|
let(:user) { create(:unconfirmed_user) }
|
2014-02-12 18:51:25 +00:00
|
|
|
|
|
|
|
it "responds with 404" do
|
|
|
|
expect(subject).to be_not_found
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-12 19:51:01 +00:00
|
|
|
context "when fictional username given" do
|
|
|
|
let(:username) { 'nononono-no' }
|
2014-02-12 18:51:25 +00:00
|
|
|
|
|
|
|
it "responds with 404" do
|
|
|
|
expect(subject).to be_not_found
|
|
|
|
end
|
|
|
|
end
|
2012-04-09 21:53:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#edit' do
|
2014-03-16 17:34:37 +00:00
|
|
|
subject { get :edit }
|
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
login_as(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is successful" do
|
|
|
|
subject
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders "edit" template' do
|
|
|
|
subject
|
|
|
|
expect(response).to render_template(:edit)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for guest user" do
|
|
|
|
before do
|
|
|
|
logout
|
|
|
|
end
|
|
|
|
|
|
|
|
it "redirects to login page" do
|
|
|
|
subject
|
2014-10-12 18:36:31 +00:00
|
|
|
expect(response).to redirect_to(new_login_path)
|
2014-03-16 17:34:37 +00:00
|
|
|
end
|
|
|
|
end
|
2012-04-09 21:53:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#update' do
|
2014-04-12 10:39:59 +00:00
|
|
|
subject { put :update, user: { username: new_username } }
|
2014-03-16 17:34:37 +00:00
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
2014-04-12 10:39:59 +00:00
|
|
|
let(:new_username) { 'batman' }
|
2014-03-16 17:34:37 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
login_as(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "redirects to profile" do
|
|
|
|
subject
|
2014-10-12 18:36:31 +00:00
|
|
|
expect(response).to redirect_to(public_profile_path(username: 'batman'))
|
2014-03-16 17:34:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when update fails" do
|
2014-04-12 10:39:59 +00:00
|
|
|
let(:new_username) { '' }
|
2014-03-16 17:34:37 +00:00
|
|
|
|
|
|
|
it "responds with 422 status code" do
|
|
|
|
subject
|
|
|
|
expect(response.status).to eq(422)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders "edit" template' do
|
|
|
|
subject
|
|
|
|
expect(response).to render_template(:edit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for guest user" do
|
|
|
|
before do
|
|
|
|
logout
|
|
|
|
end
|
|
|
|
|
|
|
|
it "redirects to login page" do
|
|
|
|
subject
|
2014-10-12 18:36:31 +00:00
|
|
|
expect(response).to redirect_to(new_login_path)
|
2014-03-16 17:34:37 +00:00
|
|
|
end
|
|
|
|
end
|
2012-04-09 21:53:38 +00:00
|
|
|
end
|
2013-10-19 18:59:39 +00:00
|
|
|
|
2012-03-04 22:07:45 +00:00
|
|
|
end
|