Skip to content

Commit

Permalink
Update ruby hash syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Amol Udage authored and LeFnord committed Jan 21, 2021
1 parent 4fb64f3 commit 9236f2e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
13 changes: 6 additions & 7 deletions lib/acts_as_follower/follow_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@ module FollowScopes

# returns Follow records where follower is the record passed in.
def for_follower(follower)
where(:follower_id => follower.id,
:follower_type => parent_class_name(follower))
where(follower_id: follower.id, follower_type: parent_class_name(follower))
end

# returns Follow records where followable is the record passed in.
def for_followable(followable)
where(:followable_id => followable.id, :followable_type => parent_class_name(followable))
where(followable_id: followable.id, followable_type: parent_class_name(followable))
end

# returns Follow records where follower_type is the record passed in.
def for_follower_type(follower_type)
where(:follower_type => follower_type)
where(follower_type: follower_type)
end

# returns Follow records where followeable_type is the record passed in.
def for_followable_type(followable_type)
where(:followable_type => followable_type)
where(followable_type: followable_type)
end

# returns Follow records from past 2 weeks with default parameter.
Expand All @@ -34,12 +33,12 @@ def descending

# returns unblocked Follow records.
def unblocked
where(:blocked => false)
where(blocked: false)
end

# returns blocked Follow records.
def blocked
where(:blocked => true)
where(blocked: true)
end

end
Expand Down
5 changes: 2 additions & 3 deletions lib/acts_as_follower/followable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def self.included(base)

module ClassMethods
def acts_as_followable
has_many :followings, :as => :followable, :dependent => :destroy, :class_name => 'Follow'
has_many :followings, as: :followable, dependent: :destroy, class_name: 'Follow'
include ActsAsFollower::Followable::InstanceMethods
include ActsAsFollower::FollowerLib
end
Expand Down Expand Up @@ -102,14 +102,13 @@ def get_follow_for(follower)
private

def block_future_follow(follower)
Follow.create(:followable => self, :follower => follower, :blocked => true)
Follow.create(followable: self, follower: follower, blocked: true)
end

def block_existing_follow(follower)
get_follow_for(follower).block!
end

end

end
end
3 changes: 1 addition & 2 deletions lib/acts_as_follower/follower.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def self.included(base)

module ClassMethods
def acts_as_follower
has_many :follows, :as => :follower, :dependent => :destroy
has_many :follows, as: :follower, dependent: :destroy
include ActsAsFollower::Follower::InstanceMethods
include ActsAsFollower::FollowerLib
end
Expand Down Expand Up @@ -108,6 +108,5 @@ def get_follow(followable)
end

end

end
end
9 changes: 4 additions & 5 deletions test/acts_as_followable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
should "accept AR options" do
@bob = FactoryGirl.create(:bob)
@bob.follow(@jon)
assert_equal 1, @jon.followers(:limit => 1).count
assert_equal 1, @jon.followers(limit: 1).count
end
end

Expand All @@ -80,8 +80,8 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
@jon.destroy
end

should_change("follow count", :by => -1) { Follow.count }
should_change("@sam.all_following.size", :by => -1) { @sam.all_following.size }
should_change("follow count", by: -1) { Follow.count }
should_change("@sam.all_following.size", by: -1) { @sam.all_following.size }
end

context "get follow record" do
Expand All @@ -107,7 +107,7 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
end

should "accept AR options" do
assert_equal 1, @jon.blocks(:limit => 1).count
assert_equal 1, @jon.blocks(limit: 1).count
end
end

Expand Down Expand Up @@ -264,5 +264,4 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
end

end

end
22 changes: 11 additions & 11 deletions test/acts_as_follower_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class ActsAsFollowerTest < ActiveSupport::TestCase
@jon.follow(@sam)
end

should_change("Follow count", :by => 1) { Follow.count }
should_change("@jon.follow_count", :by => 1) { @jon.follow_count }
should_change("Follow count", by: 1) { Follow.count }
should_change("@jon.follow_count", by: 1) { @jon.follow_count }

should "set the follower" do
assert_equal @jon, Follow.last.follower
Expand Down Expand Up @@ -77,8 +77,8 @@ class ActsAsFollowerTest < ActiveSupport::TestCase
@sam.stop_following(@jon)
end

should_change("Follow count", :by => -1) { Follow.count }
should_change("@sam.follow_count", :by => -1) { @sam.follow_count }
should_change("Follow count", by: -1) { Follow.count }
should_change("@sam.follow_count", by: -1) { @sam.follow_count }
end

context "follows" do
Expand All @@ -96,7 +96,7 @@ class ActsAsFollowerTest < ActiveSupport::TestCase
should "accept AR options" do
@metallica = FactoryGirl.create(:metallica)
@sam.follow(@metallica)
assert_equal 1, @sam.follows_by_type('Band', :limit => 1).count
assert_equal 1, @sam.follows_by_type('Band', limit: 1).count
end
end

Expand All @@ -121,7 +121,7 @@ class ActsAsFollowerTest < ActiveSupport::TestCase
end

should "accept AR options" do
assert_equal 1, @sam.all_follows(:limit => 1).count
assert_equal 1, @sam.all_follows(limit: 1).count
end
end
end
Expand All @@ -135,11 +135,11 @@ class ActsAsFollowerTest < ActiveSupport::TestCase
end

should "accept AR limit option" do
assert_equal 1, @sam.all_following(:limit => 1).count
assert_equal 1, @sam.all_following(limit: 1).count
end

should "accept AR where option" do
assert_equal 1, @sam.all_following(:where => { :id => @oasis.id }).count
assert_equal 1, @sam.all_following(where: { id: @oasis.id }).count
end
end

Expand All @@ -152,7 +152,7 @@ class ActsAsFollowerTest < ActiveSupport::TestCase
should "accept AR options" do
@metallica = FactoryGirl.create(:metallica)
@sam.follow(@metallica)
assert_equal 1, @sam.following_by_type('Band', :limit => 1).to_a.size
assert_equal 1, @sam.following_by_type('Band', limit: 1).to_a.size
end
end

Expand Down Expand Up @@ -193,8 +193,8 @@ class ActsAsFollowerTest < ActiveSupport::TestCase
@jon.destroy
end

should_change("Follow.count", :by => -1) { Follow.count }
should_change("@sam.follow_count", :by => -1) { @sam.follow_count }
should_change("Follow.count", by: -1) { Follow.count }
should_change("@sam.follow_count", by: -1) { @sam.follow_count }
end

context "blocked by followable" do
Expand Down

0 comments on commit 9236f2e

Please sign in to comment.