diff --git a/app/models/poll/booth_assignment.rb b/app/models/poll/booth_assignment.rb index e3529e06a..3af585e77 100644 --- a/app/models/poll/booth_assignment.rb +++ b/app/models/poll/booth_assignment.rb @@ -5,7 +5,7 @@ class Poll delegate :name, to: :booth - before_destroy :destroy_poll_shifts, only: :destroy + before_destroy :destroy_poll_shifts has_many :officer_assignments, dependent: :destroy has_many :officers, through: :officer_assignments diff --git a/app/views/proposals/created.html.erb b/app/views/proposals/created.html.erb index 6dba6ab68..1c9ed9fae 100644 --- a/app/views/proposals/created.html.erb +++ b/app/views/proposals/created.html.erb @@ -27,4 +27,4 @@ -<%= render file: "proposals/show.html.erb", locals: { preview: true } %> +<%= render template: "proposals/show", locals: { preview: true } %> diff --git a/config/initializers/acts_as_taggable_on.rb b/config/initializers/acts_as_taggable_on.rb index 16d3d6845..d9ec982a4 100644 --- a/config/initializers/acts_as_taggable_on.rb +++ b/config/initializers/acts_as_taggable_on.rb @@ -4,12 +4,11 @@ module ActsAsTaggableOn after_destroy :touch_taggable, :decrement_tag_custom_counter scope :public_for_api, -> do - where(%{taggings.tag_id in (?) and - (taggings.taggable_type = 'Debate' and taggings.taggable_id in (?)) or - (taggings.taggable_type = 'Proposal' and taggings.taggable_id in (?))}, - Tag.where("kind IS NULL or kind = ?", "category").pluck(:id), - Debate.public_for_api.pluck(:id), - Proposal.public_for_api.pluck(:id)) + where( + # TODO: remove default_scoped after upgrading to Rails 6.1 + tag: Tag.default_scoped.where(kind: [nil, "category"]), + taggable: [Debate.public_for_api, Proposal.public_for_api] + ) end def touch_taggable @@ -35,9 +34,10 @@ module ActsAsTaggableOn include Graphqlable scope :public_for_api, -> do - where("(tags.kind IS NULL or tags.kind = ?) and tags.id in (?)", - "category", - Tagging.public_for_api.distinct.pluck("taggings.tag_id")) + where( + kind: [nil, "category"], + id: Tagging.public_for_api.distinct.pluck(:tag_id) + ) end include PgSearch::Model diff --git a/spec/components/sdg/related_list_selector_component_spec.rb b/spec/components/sdg/related_list_selector_component_spec.rb index f06280fa0..07f5893b1 100644 --- a/spec/components/sdg/related_list_selector_component_spec.rb +++ b/spec/components/sdg/related_list_selector_component_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" describe SDG::RelatedListSelectorComponent do let(:debate) { create(:debate) } - let(:form) { ConsulFormBuilder.new(:debate, debate, ActionView::Base.new, {}) } + let(:form) { ConsulFormBuilder.new(:debate, debate, ApplicationController.new.view_context, {}) } let(:component) { SDG::RelatedListSelectorComponent.new(form) } before do diff --git a/spec/lib/consul_form_builder_spec.rb b/spec/lib/consul_form_builder_spec.rb index ed73b6b62..a61e984da 100644 --- a/spec/lib/consul_form_builder_spec.rb +++ b/spec/lib/consul_form_builder_spec.rb @@ -11,7 +11,7 @@ describe ConsulFormBuilder do stub_const("DummyModel::OPTIONS", %w[Good Bad Ugly].freeze) end - let(:builder) { ConsulFormBuilder.new(:dummy, DummyModel.new, ActionView::Base.new, {}) } + let(:builder) { ConsulFormBuilder.new(:dummy, DummyModel.new, ApplicationController.new.view_context, {}) } describe "hints" do it "does not generate hints by default" do diff --git a/spec/models/tagging_spec.rb b/spec/models/tagging_spec.rb new file mode 100644 index 000000000..7fc7c0938 --- /dev/null +++ b/spec/models/tagging_spec.rb @@ -0,0 +1,21 @@ +require "rails_helper" + +describe Tagging do + describe ".public_for_api" do + it "returns taggings for debates and proposals" do + create(:tag, name: "Health", kind: nil) + debate = create(:debate, tag_list: "Health") + proposal = create(:proposal, tag_list: "Health") + + expect(Tagging.public_for_api.map(&:taggable)).to match_array [debate, proposal] + end + + it "does not return taggings for other tag kinds" do + create(:tag, name: "Health", kind: "custom") + create(:debate, tag_list: "Health") + create(:proposal, tag_list: "Health") + + expect(Tagging.public_for_api.map(&:taggable)).to be_empty + end + end +end