Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe TokensController do
- before(:each) do
- @mock_user = User.new(:username => "bob", :email => "user@user.com", :password => "longpassword")
- @mock_user.role = "admin"
- sign_in @mock_user
- #Ability.stub!('can').and_return(true)
- end
- it "should let me see grids/:g_id/tokens index" do
- test_grid = mock_model(Grid)
- test_token = mock_model(Token)
- Grid.stub!(:find).and_return(test_grid)
- Token.stub!(:find).and_return(test_token)
- get 'index'
- a1 = Ability.new(@mock_user)
- a1.can?(:index, Token).should be_true # This line works fine; as it should
- puts response.status #This returns 403, which means CanCan::AccessDenied was raised
- end
- end
- authorize! :take_over, @the_world
- before do
- @user = Factory.create(:user)
- sign_in @user
- @abilities = Ability.new(@user)
- Ability.stub(:new).and_return(@abilities)
- end
- end
- user = User.create!(:admin => true) # I recommend a factory for this
- # log in user however you like, alternatively stub `current_user` method
- session[:user_id] = user.id
- get :index
- assert_template :index # render the template since he should have access
- def setup
- @ability = Object.new
- @ability.extend(CanCan::Ability)
- @controller.stubs(:current_ability).returns(@ability)
- end
- test "render index if have read ability on project" do
- @ability.can :read, Project
- get :index
- assert_template :index
- end
- can :manage, :all do
- user.is_ultrasuper == 1
- end
- one:
- id: 1
- username: my_username
- is_ultrasuper: 1
- let!(:user) {create :user}
- before { login_user_request user}
- it "grants admin access to show action" do
- expect{ get :show, {id: user.id} }.to be_authorized
- end
- it "denies user access to edit action" do
- expect{ get :edit, {id: user.id} }.to be_un_authorized
- end
- RSpec::Matchers.define :be_authorized do
- match do |block|
- block.call
- expect(response).to be_success
- end
- def supports_block_expectations?
- true
- end
- end
- RSpec::Matchers.define :be_un_authorized do
- match do |block|
- expect{
- block.call
- }.to raise_error(Pundit::NotAuthorizedError)
- end
- def supports_block_expectations?
- true
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement