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
Thomas Slater
5,094 PointsRails: Managing friendships error
I'm on the final tutorial for the social features on rails, and I'm on the very last part of that too.
I keep getting this error:
test_should_not_display_blocked_user's_posts_when_logged_in(StatusesControllerTe
st) [test/functional/statuses_controller_test.rb:29]:
</Blocked\ status/> expected to not match
But in my statuses_controller_test, I have in relation to this:
test "should display user's posts when not logged in" do
users(:blocked_friend).statuses.create(content: 'Blocked status')
users(:gandalf).statuses.create(content: 'Non-blocked status')
get :index
assert_match /Non\-blocked status/, response.body
assert_match /Blocked\ status/, response.body
end
test "should not display blocked user's posts when logged in" do
sign_in users(:baggins)
users(:blocked_friend).statuses.create(content: 'Blocked status')
users(:gandalf).statuses.create(content: 'Non-blocked status')
get :index
assert_match /Non\-blocked status/, response.body
assert_no_match /Blocked\ status/, response.body
end
I have this in the index: <% if can_display_status?(status) %>
which refers to this in the app helper:
def can_display_status?(status)
signed_in? && !current_user.has_blocked?(status.user) || !signed_in?
end
this is from user.rb:
def has_blocked?(other_user) blocked_friends.include?(other_user) end
this is from the user_test:
context "#has_blocked?" do
should "return true if a user has blocked another user" do
assert users(:baggins).has_blocked?(users(:blocked_friend))
end
should "return false if a user has not blocked another user" do
assert !users(:baggins).has_blocked?(users(:gandalf))
end
end
I've checked against the uploaded files, and I just don't see where I'm going wrong here. Sorry for the long post, there's just a lot of code involved.
3 Answers
Nick Pettit
Treehouse TeacherHi Thomas Slater,
Sorry for the slow reply. This week Jason Seifer is speaking at a conference, but he should be able to get back to you soon!
Nick
Thomas Slater
5,094 PointsHey Thanks for the note, Nick! Much appreciated, by the way I enjoy your presentations. Anyway, I actually just fixed this one, it was a very difficult one to find! It was a problem of ordering in my user_friendship model. Weird.
Jason Seifer
Treehouse Guest TeacherHey Thomas,
I'm not 100% sure this will work since I can't see your whole project code but try changing this:
def can_display_status?(status)
signed_in? && !current_user.has_blocked?(status.user) || !signed_in?
end
To this:
def can_display_status?(status)
(signed_in? && !current_user.has_blocked?(status.user)) || !signed_in?
end