Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove acts_as_list from Content #1798

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions app/models/alchemy/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,25 @@ class Content < BaseRecord

stampable stamper_class_name: Alchemy.user_class_name

acts_as_list scope: [:element_id]

# Essence scopes
scope :essence_booleans, -> { where(essence_type: "Alchemy::EssenceBoolean") }
scope :essence_dates, -> { where(essence_type: "Alchemy::EssenceDate") }
scope :essence_files, -> { where(essence_type: "Alchemy::EssenceFile") }
scope :essence_htmls, -> { where(essence_type: "Alchemy::EssenceHtml") }
scope :essence_links, -> { where(essence_type: "Alchemy::EssenceLink") }
scope :essence_pictures, -> { where(essence_type: "Alchemy::EssencePicture") }
scope :essence_booleans, -> { where(essence_type: "Alchemy::EssenceBoolean") }
scope :essence_dates, -> { where(essence_type: "Alchemy::EssenceDate") }
scope :essence_files, -> { where(essence_type: "Alchemy::EssenceFile") }
scope :essence_htmls, -> { where(essence_type: "Alchemy::EssenceHtml") }
scope :essence_links, -> { where(essence_type: "Alchemy::EssenceLink") }
scope :essence_pictures, -> { where(essence_type: "Alchemy::EssencePicture") }
scope :essence_richtexts, -> { where(essence_type: "Alchemy::EssenceRichtext") }
scope :essence_selects, -> { where(essence_type: "Alchemy::EssenceSelect") }
scope :essence_texts, -> { where(essence_type: "Alchemy::EssenceText") }
scope :named, ->(name) { where(name: name) }
scope :available, -> { published.not_trashed }
scope :published, -> { joins(:element).merge(Element.published) }
scope :not_trashed, -> { joins(:element).merge(Element.not_trashed) }
scope :not_restricted, -> { joins(:element).merge(Element.not_restricted) }

delegate :restricted?, to: :page, allow_nil: true
delegate :trashed?, to: :element, allow_nil: true
delegate :public?, to: :element, allow_nil: true
scope :essence_selects, -> { where(essence_type: "Alchemy::EssenceSelect") }
scope :essence_texts, -> { where(essence_type: "Alchemy::EssenceText") }
scope :named, ->(name) { where(name: name) }
scope :available, -> { published.not_trashed }
scope :published, -> { joins(:element).merge(Element.published) }
scope :not_trashed, -> { joins(:element).merge(Element.not_trashed) }
scope :not_restricted, -> { joins(:element).merge(Element.not_restricted) }

delegate :restricted?, to: :page, allow_nil: true
delegate :trashed?, to: :element, allow_nil: true
delegate :public?, to: :element, allow_nil: true

class << self
# Returns the translated label for a content name.
Expand Down
2 changes: 1 addition & 1 deletion app/models/alchemy/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Element < BaseRecord

stampable stamper_class_name: Alchemy.user_class_name

has_many :contents, -> { order(:position) }, dependent: :destroy, inverse_of: :element
has_many :contents, dependent: :destroy, inverse_of: :element

has_many :all_nested_elements,
-> { order(:position).not_trashed },
Expand Down
1 change: 0 additions & 1 deletion app/serializers/alchemy/content_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class ContentSerializer < ActiveModel::Serializer
:name,
:ingredient,
:element_id,
:position,
:created_at,
:updated_at,
:settings
Expand Down
3 changes: 1 addition & 2 deletions db/migrate/20200226213334_alchemy_four_point_four.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ def up
t.string "essence_type", null: false
t.integer "essence_id", null: false
t.integer "element_id", null: false
t.integer "position"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "creator_id"
t.integer "updater_id"
t.index ["element_id", "position"], name: "index_contents_on_element_id_and_position"
t.index ["element_id"], name: "index_contents_on_element_id"
t.index ["essence_id", "essence_type"], name: "index_alchemy_contents_on_essence_id_and_essence_type", unique: true
end
end
Expand Down
3 changes: 1 addition & 2 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@
t.string "essence_type", null: false
t.integer "essence_id", null: false
t.integer "element_id", null: false
t.integer "position"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "creator_id"
t.integer "updater_id"
t.index ["element_id", "position"], name: "index_contents_on_element_id_and_position"
t.index ["element_id"], name: "index_contents_on_element_id"
t.index ["essence_id", "essence_type"], name: "index_alchemy_contents_on_essence_id_and_essence_type", unique: true
end

Expand Down
17 changes: 0 additions & 17 deletions spec/models/alchemy/element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,23 +398,6 @@ module Alchemy
end
end

describe "#contents" do
let(:element) { create(:alchemy_element) }
let!(:content1) { create(:alchemy_content, element: element) }
let!(:content2) { create(:alchemy_content, element: element) }

subject { element.contents }

before do
content1.update_column(:position, 2)
content2.update_column(:position, 1)
end

it "are ordered by position" do
is_expected.to eq([content2, content1])
end
end

describe "#content_by_type" do
before(:each) do
@element = create(:alchemy_element, name: "headline")
Expand Down