Search code examples
ruby-on-railsgravatar

ruby on rails gravatar_image_tag


I am following the railstutorial.org tutorial. While I am able to see the gravatar on the webpage, my rspec test is failing.

Here is the user_controller_spec.rb test:

describe "GET 'show'" do

  before(:each) do
    @user = Factory(:user)
  end

  it "should be successful" do
    get :show, :id => @user
    response.should be_success
  end

end

Here is the relevant show.html.erb file:

<table class="profile" summary="Profile information">
  <tr>
    <td class="main">
      <h1>
        <%= gravatar_image_tag(@user.email) %>
        <%= @user.name %>
      </h1>
    </td>
    <td class="sidebar round">
      <strong>Name</strong> <%= @user.name %><br />
      <strong>URL</strong> <%= link_to user_path(@user), @user %>
    </td>
  </tr>
</table>

I get an error stating "undefined method 'gravatar_image_tag'. I already installed the corresponding gem by executing "gem install gravatar_image_tag", added it to my gemfile, and also executed "bundle install". It is listed as installed when I execute "gem list"

I have been trying to debug this for several hours now. Any help would be appreciated. Thanks in advance. BTW, I'm running 32-bit Windows 7 with GIT Bash, RubyInstaller-1.9.2-p0.

Error message:

alt text


Solution

  • Is the gravatar_image_tag gem global to all environments in your gemfile? If you have it in a group :development, :production block, or something similar, it wouldn't be available in test.

    And I haven't tried it, but your line:

    get :show, :id => @user

    seems like it needs to be:

    get :show, :id => @user.id