Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing #182

Merged
merged 8 commits into from Feb 14, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 53 additions & 0 deletions spec/controllers/user_controller_spec.rb
@@ -0,0 +1,53 @@
require 'spec_helper'

describe UsersController do
let(:bob){Fabricate(:user)}
let(:mozart){Fabricate(:user)}

describe '#index' do
context "When user is no moderator" do
it "try to get index" do
get :index
expect(response).to redirect_to(root_path)
end
end

context "When user is moderator" do
before { sign_in Fabricate(:user, moderator: true) }
it "gets index with authorization" do
get :index
response.should be_success
end
end
end

describe 'Following actions' do
before { sign_in bob }
it 'Try to follow himself' do
post :follow, user_id: bob, :user => {:followee => bob.id}
expect(flash[:notice]).to eq("You can't follow yourself silly!")
end

it '#follow just once' do
post :follow, user_id: bob, :user => {:followee => mozart.id}
expect(flash[:notice]).to eq("You're following #{mozart.username} now")
post :follow, user_id: bob, :user => {:followee => mozart.id}
expect(flash[:notice]).to eq("You're already following #{mozart.username}")
end

it '#following?' do
get :following, user_id: bob
response.should be_success
end

it '#followers' do
get :followers, user_id: bob
response.should be_success
end

it '#unfollow' do
post :unfollow, user_id: bob, :user => {:followee => mozart.id}
expect(flash[:notice]).to eq("You're no longer following #{mozart.username}")
end
end
end