Merge pull request #4789 from consul/rails_6.0_compatibility

Add Rails 6.0 compatibility
This commit is contained in:
Javi Martín
2022-03-23 14:14:11 +01:00
committed by GitHub
6 changed files with 34 additions and 13 deletions

View File

@@ -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

View File

@@ -27,4 +27,4 @@
</div>
</div>
<%= render file: "proposals/show.html.erb", locals: { preview: true } %>
<%= render template: "proposals/show", locals: { preview: true } %>

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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