mercredi 8 avril 2015

`permitted_to?` in helper causing exception with rspec using `declarative_authorization`

I am writing rspec for helper. But getting error while using `permitted_to?' in helper.


It works fine in application but in test case it causing error.


Code



module PostModule
module ApplicationHelper
def link_for_post(post)
if can_edit_post?(post)
edit_post_path(post)
else
posts_path
end
end

def can_edit_post?(post)
permitted_to?(:edit, post, :context => :post_module_posts)
end
end
end


Rspec



describe PostModule::ApplicationHelper do
describe '#link_for_post' do
let(:user) { FactoryGirl.create(:user) }
let(:first_post) {stub_model(PostModule::Post, {id: 1 })}
it "should return edit link if has permission" do
can_edit_post?(post).and_return(true)
link_for_post(post).should eq('/posts/1/edit')
end
it "should return index path" do
can_edit_post?(post).and_return(false)
link_for_post(post).should eq('/posts')
end
end
end


Error



Failure/Error: can_edit_post?(post).and_return(true)
NoMethodError:
undefined method `permitted_to?' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x0000001209b8e0>

Aucun commentaire:

Enregistrer un commentaire