|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe UsersController do |
| 4 | + let(:bob){Fabricate(:user)} |
| 5 | + let(:mozart){Fabricate(:user)} |
| 6 | + |
| 7 | + describe('#index') do |
| 8 | + context "When user is no moderator" do |
| 9 | + it "try to get index" do |
| 10 | + get :index |
| 11 | + response.should redirect_to(root_path) |
| 12 | + end |
| 13 | + end |
| 14 | + |
| 15 | + context "When user is moderator" do |
| 16 | + before { sign_in Fabricate(:user, moderator: true) } |
| 17 | + it "gets index with authorization" do |
| 18 | + get :index |
| 19 | + response.should be_success |
| 20 | + end |
| 21 | + end |
| 22 | + end |
| 23 | + |
| 24 | + describe 'Following actions' do |
| 25 | + before { sign_in bob } |
| 26 | + it('Try to follow himself') do |
| 27 | + post :follow, user_id: bob, :user => {:followee => bob.id} |
| 28 | + expect(flash[:notice]).to eq("You can't follow yourself silly!") |
| 29 | + end |
| 30 | + |
| 31 | + it('#follow just once') do |
| 32 | + post :follow, user_id: bob, :user => {:followee => mozart.id} |
| 33 | + expect(flash[:notice]).to eq("You're following #{mozart.username} now") |
| 34 | + post :follow, user_id: bob, :user => {:followee => mozart.id} |
| 35 | + expect(flash[:notice]).to eq("You're already following #{mozart.username}") |
| 36 | + end |
| 37 | + |
| 38 | + it('#following?') do |
| 39 | + get :following, user_id: bob |
| 40 | + response.should be_success |
| 41 | + end |
| 42 | + |
| 43 | + it ('#followers') do |
| 44 | + get :followers, user_id: bob |
| 45 | + response.should be_success |
| 46 | + end |
| 47 | + |
| 48 | + it ('#unfollow') do |
| 49 | + post :unfollow, user_id: bob, :user => {:followee => mozart.id} |
| 50 | + expect(flash[:notice]).to eq("You're no longer following #{mozart.username}") |
| 51 | + end |
| 52 | + end |
| 53 | +end |
0 commit comments