2013-06-05 31 views
0

我有一个失败的rspec测试,我似乎无法弄清楚什么是错的。这个方法是明确定义的,它在网站上运行;只是没有通过测试。未定义的方法`gravatar_for'设计编辑注册路径

UserPages edit with invalid information 
Failure/Error: visit edit_user_registration_path(user) 
ActionView::Template::Error: 
    undefined method `gravatar_for' for_app_views_devise_registrations_edit_html_erb 
# ./app/views/devise/registrations/edit.html.erb:8:in 
`_app_views_devise_registrations_edit_html_erb 
# ./spec/requests/user_pages_spec.rb:114:in `block (3 levels) in <top (required)>' 

这里是RSpec的测试:

describe "edit" do 
    let(:user) {FactoryGirl.create(:user)} 
    before do 
     sign_in user 
     visit edit_user_registration_path(user) 
    end 

    describe "page" do 


     it { should have_selector('h1', text: "Update your profile")} 
     it { should have_selector('title', text: "Edit user")} 
     it { should have_link('change', href: "http://gravatar.com/emails")} 
    end 

    describe "with invalid information" do 
     before { click_button "Save changes"} 
     it { should have_content('error')} 

下面是实际的方法:

module UsersHelper 
#Returns the Gravatar for the given user. 
def gravatar_for(user, options = { size: 50}) 
    gravatar_id = Digest::MD5::hexdigest(user.email.downcase) 
    size = options[:size] 
    gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}" 
    image_tag(gravatar_url, alt: user.name, class: "gravatar") 
end 
    end 

最后是代码视图本身:

<%= gravatar_for @user %> 
    <a href="http://gravatar.com/emails" target="_blank">change avatar</a> 

回答

0

你方法在中定义,但您的观点是Devise::Registration。因此,您应该转移到适当的帮手,应用程序帮助程序,或者创建一个共享UserDevise::Registration方法的类,并包含在这两个帮助程序中。

+1

谢谢你,工作。 –

相关问题