-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2451 from manyfold3d/following
Refactor list code to be more easily reusable
- Loading branch information
Showing
8 changed files
with
63 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Listable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
acts_as_favoritable | ||
end | ||
|
||
def listers(list_name) | ||
favoritors(scope: list_name) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Lister | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
acts_as_favoritor | ||
end | ||
|
||
def list(object, list_name) | ||
favorite(object, scope: list_name) | ||
end | ||
|
||
def delist(object, list_name) | ||
unfavorite(object, scope: list_name) | ||
end | ||
|
||
def set_list_state(object, list_name, listed) | ||
if listed | ||
list(object, list_name) | ||
else | ||
delist(object, list_name) | ||
end | ||
end | ||
|
||
def listed?(object, list_name) | ||
favorited?(object, scope: list_name) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
shared_examples "Listable" do | ||
let(:thing) { create(described_class.to_s.underscore.to_sym) } | ||
let(:user) { create(:user) } | ||
|
||
before do | ||
user.list(thing, :printed) | ||
end | ||
|
||
it "shows as listed" do | ||
expect(user.listed?(thing, :printed)).to be true | ||
end | ||
|
||
it "can access listers" do | ||
expect(thing.listers(:printed)).to eq [user] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Dir[Rails.root.join("spec/**/*_shared.rb")].each { |f| require f } |