Skip to content

Commit

Permalink
Merge pull request #275 from enoodle/active_admin_scopes_cleanup
Browse files Browse the repository at this point in the history
refactor 'displayed' scope with camp_manager_id
  • Loading branch information
enoodle authored Mar 8, 2018
2 parents 22baea9 + ae51107 commit 3e8adb1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
8 changes: 4 additions & 4 deletions app/admin/camps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
EXCLUDED = %w(contact_email user_id seeking_members safetybag_firstMemberName safetybag_firstMemberEmail safetybag_secondMemberName safetybag_secondMemberEmail)

scope :active, default: true do |dreams|
dreams.active(true)
dreams.displayed.where(active: true)
end
scope :displayed_with_tags, default: false
scope("Public") { |scope| scope.where(is_public: true) }
scope("Private") { |scope| scope.where(is_public: false) }
scope("Inactive") { |scope| scope.where(active: false) }
scope("Public") { |dreams| dreams.displayed.where(is_public: true) }
scope("Private") { |dreams| dreams.displayed.where(is_public: false) }
scope("Inactive") { |dreams| dreams.displayed.where(active: false) }

remove_filter *%i(tag_taggings taggings base_tags)
index do
Expand Down
6 changes: 2 additions & 4 deletions app/models/camp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,8 @@ class Camp < ActiveRecord::Base
}

scope :displayed, -> {
q = default_select.joins("LEFT JOIN roles ON (roles.identifier = '#{:manager}')")
.joins("LEFT JOIN people ON (people.camp_id = camps.id)")
.joins("LEFT JOIN people_roles pr ON (pr.role_id = roles.id)")
.where('people.id = pr.person_id')
q = default_select.joins(:people)
.where('people.id = camps.camp_manager_id')

if connection.adapter_name == 'SQLite'
q.select('people.name manager_name, people.email manager_email, people.phone_number manager_phone')
Expand Down
11 changes: 11 additions & 0 deletions spec/models/camp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@
.and_return("current_event")
end

describe "#displayed scop" do
it "displays camp" do
camp.update(camp_manager: john)
expect(Camp.displayed).to eq([camp])
end

it "doesn't display manager-less camps" do
expect(Camp.displayed).to be_empty
end
end

describe "#self.to_csv" do
context "one dream" do
it "shows a dream from current event" do
Expand Down

0 comments on commit 3e8adb1

Please sign in to comment.