spec/popular/popular_model_spec.rb in popular-0.5.1 vs spec/popular/popular_model_spec.rb in popular-0.6.0
- old
+ new
@@ -1,12 +1,21 @@
shared_examples "a popular model" do
describe 'mutual friendships' do
- it '.inverse_friends includes popular_models who have added an instance as a friend' do
- another_popular_model.befriend popular_model
+ describe '.inverse_friends' do
+ it 'includes popular_models who have added an instance as a friend' do
+ another_popular_model.befriend popular_model
- expect( popular_model ).to be_friended_by another_popular_model
+ expect( popular_model ).to be_friended_by another_popular_model
+ end
+
+ it 'can be called with followers' do
+ another_popular_model.follow popular_model
+
+ expect( popular_model ).to be_followed_by another_popular_model
+ expect( popular_model.followers ).to match_array [another_popular_model]
+ end
end
it '#mutual_friends_with? returns false if instances are not mutual friends' do
expect( popular_model ).to_not be_mutual_friends_with another_popular_model
end
@@ -18,10 +27,16 @@
expect( popular_model ).to be_mutual_friends_with another_popular_model
end
end
describe '.befriend!' do
+ it 'can be called with .follow!' do
+ popular_model.follow! another_popular_model
+
+ expect( popular_model).to be_following another_popular_model
+ end
+
it 'creates a one way friendship' do
popular_model.befriend! another_popular_model
expect( popular_model).to be_friends_with another_popular_model
end
@@ -40,11 +55,17 @@
end
end
end
describe '.befriend' do
+ it 'can be called with .follow' do
+ popular_model.follow another_popular_model
+ expect( popular_model).to be_following another_popular_model
+ end
+
+
context 'successful' do
it 'triggers before_befriend callback' do
ensure_callback_fired_on popular_model_with_callbacks, :before_befriend_callback
popular_model_with_callbacks.befriend another_popular_model
@@ -64,11 +85,11 @@
end
end
describe '#friends_with?' do
- it 'returns true if a popular_model is friends with a given popular_model' do
+ it 'returns false if a popular_model is not friends with a given popular_model' do
expect( popular_model ).to_not be_friends_with another_popular_model
end
it 'returns true if a popular_model is friends with a given popular_model' do
popular_model.befriend another_popular_model
@@ -76,9 +97,17 @@
expect( popular_model ).to be_friends_with another_popular_model
end
end
describe '.unfriend' do
+ it 'can be called with .unfollow' do
+ [:follow, :unfollow].each do |method|
+ popular_model.send method, another_popular_model
+ end
+
+ expect( popular_model).to_not be_following another_popular_model
+ end
+
it 'destroys a friendship' do
[:befriend, :unfriend].each do |method|
popular_model.send method, another_popular_model
end