Start writing Group tests.
This commit is contained in:
parent
0d9b683100
commit
26689f3bd2
|
@ -47,7 +47,7 @@ class GroupsController < ApplicationController
|
||||||
|
|
||||||
if @group.save
|
if @group.save
|
||||||
flash[:notice] = t('flash.group.saved')
|
flash[:notice] = t('flash.group.saved')
|
||||||
redirect_to edit_group_path(@group)
|
redirect_to group_path(@group)
|
||||||
else
|
else
|
||||||
flash[:error] = t('flash.group.save_error')
|
flash[:error] = t('flash.group.save_error')
|
||||||
flash[:warning] = @group.errors[:base]
|
flash[:warning] = @group.errors[:base]
|
||||||
|
@ -58,7 +58,7 @@ class GroupsController < ApplicationController
|
||||||
def update
|
def update
|
||||||
if @group.update_attributes(params[:group])
|
if @group.update_attributes(params[:group])
|
||||||
flash[:notice] = t('flash.group.saved')
|
flash[:notice] = t('flash.group.saved')
|
||||||
redirect_to groups_path
|
redirect_to group_path(@group)
|
||||||
else
|
else
|
||||||
flash[:error] = t('flash.group.save_error')
|
flash[:error] = t('flash.group.save_error')
|
||||||
render :action => :edit
|
render :action => :edit
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe GroupsController do
|
||||||
|
before(:each) do
|
||||||
|
@group = Factory(:group)
|
||||||
|
@another_user = Factory(:user)
|
||||||
|
@create_params = {:group => {:name => 'grp1', :uname => 'un_grp1'}}
|
||||||
|
@update_params = {:group => {:name => 'grp2'}}
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'for guest' do
|
||||||
|
it 'should not be able to perform index action' do
|
||||||
|
get :index
|
||||||
|
response.should redirect_to(new_user_session_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not be able to perform update action' do
|
||||||
|
put :update, {:id => @group.id}.merge(@update_params)
|
||||||
|
response.should redirect_to(new_user_session_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'for admin' do
|
||||||
|
before(:each) do
|
||||||
|
@admin = Factory(:admin)
|
||||||
|
set_session_for(@admin)
|
||||||
|
end
|
||||||
|
|
||||||
|
it_should_behave_like 'be_able_to_perform_index#groups'
|
||||||
|
it_should_behave_like 'be_able_to_perform_update#groups'
|
||||||
|
it_should_behave_like 'update_member_relation'
|
||||||
|
|
||||||
|
it 'should be able to perform create action' do
|
||||||
|
post :create, @create_params
|
||||||
|
response.should redirect_to(group_path( Group.last.id ))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should change objects count on create' do
|
||||||
|
lambda { post :create, @create_params }.should change{ Group.count }.by(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe MembersController do
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
Factory.define(:group) do |g|
|
||||||
|
g.name { Factory.next(:string) }
|
||||||
|
g.uname { Factory.next(:uname) }
|
||||||
|
g.association :owner, :factory => :user
|
||||||
|
end
|
|
@ -0,0 +1,15 @@
|
||||||
|
shared_examples_for 'be_able_to_perform_index#groups' do
|
||||||
|
it 'should be able to perform index action' do
|
||||||
|
get :index
|
||||||
|
response.should render_template(:index)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples_for 'be_able_to_perform_update#groups' do
|
||||||
|
it 'should be able to perform update action' do
|
||||||
|
put :update, {:id => @group.id}.merge(@update_params)
|
||||||
|
response.should redirect_to(group_path(@group))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
shared_examples_for 'update_member_relation' do
|
||||||
|
it 'should update member relation' do
|
||||||
|
@another_user.relations.exists? :target_id => @group.id, :target_type => 'Group', :role => 'read'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue