asciinema.org/spec/controllers/users_controller_spec.rb

112 lines
2.1 KiB
Ruby
Raw Normal View History

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 19:51:01 +00:00
let(:username) { user.username }
before do
subject
end
2014-10-05 16:25:49 +00:00
context "when confirmed user username given" do
let(:user) { create(:user) }
it 'renders "show" template' do
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) }
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' }
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
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)
end
end
2012-04-09 21:53:38 +00:00
end
describe '#update' do
subject { put :update, user: { username: new_username } }
let(:user) { create(:user) }
let(:new_username) { 'batman' }
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'))
end
context "when update fails" do
let(:new_username) { '' }
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)
end
end
2012-04-09 21:53:38 +00:00
end
2012-03-04 22:07:45 +00:00
end