Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

"What is a State Machine?" Lesson user_notifier error

Hey guys, I ran into an error at the end of the lesson:

C:\Sites\Projects\treebook>ruby -I test test/unit/user_friendship_test.rb

1) Error:

test: #send_request_email should send an email. (UserFriendshipTest):
NoMethodError: undefined method `friend' for UserNotifier:Class

I've been comparing both my user_notifier.rb and my user_friendship_test.rb to the lesson and I don't see my error.

The test:

context "#send_request_email" do
  setup do
    @user_friendship = UserFriendship.create user: users(:allan), friend: users(:mike)
  end

  should "send an email" do
    assert_difference 'ActionMailer::Base.deliveries.size', 1 do
      @user_friendship.send_request_email
    end
  end
end

user_notifier.rb :

class UserNotifier < ActionMailer::Base
  default from: "from@example.com"

  def friend_requested(user_friendship_id)
    user_friendship = UserFriendship.find(user_friendship_id)

    @user = user_friendship.user
    @friend = user_friendship.friend

    mail to: @friend.email,
        subject: "#{@user.first_name} wants to be friends on Treebook"
    end
end

Let me know if any ideas hit you, thanks.

4 Answers

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Allan, what does your friend_requested template look like? Can you paste it here? Thanks!

I just copied it straight from the video:

Hi <%= @friend.first_name %>,

<%= @user.first_name %> wants to be friends on Treebook. Isn't that great?

Love, Mike the Frog

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Can you zip up your project and email it to help@teamtreehouse.com? I'll need to see a bit more of the code and run it in order to get an idea of what's wrong.

Hey Jason did you recurve the zipped copy yet?