mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 19:27:52 +01:00
Add post status administration (#105)
This commit is contained in:
committed by
GitHub
parent
c5148147e3
commit
5256ea911a
@@ -37,7 +37,7 @@ RSpec.describe PostStatus, type: :model do
|
||||
expect(valid_color2).to be_valid
|
||||
end
|
||||
|
||||
it 'must have a order of type integer and positive' do
|
||||
it 'must have a order of type integer and non-negative' do
|
||||
nil_order = FactoryBot.build(:post_status, order: nil)
|
||||
empty_order = FactoryBot.build(:post_status, order: '')
|
||||
decimal_order = FactoryBot.build(:post_status, order: 1.1)
|
||||
@@ -48,7 +48,7 @@ RSpec.describe PostStatus, type: :model do
|
||||
expect(empty_order).to be_invalid
|
||||
expect(decimal_order).to be_invalid
|
||||
expect(negative_order).to be_invalid
|
||||
expect(zero_order).to be_invalid
|
||||
expect(zero_order).to be_valid
|
||||
end
|
||||
|
||||
it 'has a method that returns only post statuses that should show up in roadmap' do
|
||||
|
||||
33
spec/workflows/ensure_coherent_ordering_workflow_spec.rb
Normal file
33
spec/workflows/ensure_coherent_ordering_workflow_spec.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe EnsureCoherentOrderingWorkflow do
|
||||
let(:workflow_creator) {
|
||||
EnsureCoherentOrderingWorkflow.new(
|
||||
entity_classname: PostStatus,
|
||||
column_name: 'order'
|
||||
)
|
||||
}
|
||||
|
||||
it 'fills any gap in a column representing ordering' do
|
||||
post_status1 = FactoryBot.create(:post_status, order: 4)
|
||||
post_status2 = FactoryBot.create(:post_status, order: 10)
|
||||
post_status3 = FactoryBot.create(:post_status, order: 133)
|
||||
|
||||
workflow_creator.run
|
||||
|
||||
expect(post_status1.reload.order).to eq(0)
|
||||
expect(post_status2.reload.order).to eq(1)
|
||||
expect(post_status3.reload.order).to eq(2)
|
||||
|
||||
post_status2.destroy
|
||||
workflow_creator.run
|
||||
|
||||
expect(post_status1.reload.order).to eq(0)
|
||||
expect(post_status3.reload.order).to eq(1)
|
||||
|
||||
post_status1.destroy
|
||||
workflow_creator.run
|
||||
|
||||
expect(post_status3.reload.order).to eq(0)
|
||||
end
|
||||
end
|
||||
35
spec/workflows/reorder_workflow_spec.rb
Normal file
35
spec/workflows/reorder_workflow_spec.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ReorderWorkflow do
|
||||
let(:workflow_creator) {
|
||||
ReorderWorkflow.new(
|
||||
entity_classname: entity_classname,
|
||||
column_name: column_name,
|
||||
entity_id: entity_id,
|
||||
src_index: src_index,
|
||||
dst_index: dst_index
|
||||
)
|
||||
}
|
||||
|
||||
let(:entity_classname) { PostStatus }
|
||||
let(:column_name) { 'order' }
|
||||
let(:entity_id) { post_status1.id }
|
||||
let(:src_index) { post_status1.order }
|
||||
let(:dst_index) { post_status3.order }
|
||||
|
||||
let!(:post_status0) { FactoryBot.create(:post_status, order: 0) }
|
||||
let!(:post_status1) { FactoryBot.create(:post_status, order: 1) }
|
||||
let!(:post_status2) { FactoryBot.create(:post_status, order: 2) }
|
||||
let!(:post_status3) { FactoryBot.create(:post_status, order: 3) }
|
||||
let!(:post_status4) { FactoryBot.create(:post_status, order: 4) }
|
||||
|
||||
it 'reorders entities after moving one of them' do
|
||||
workflow_creator.run
|
||||
|
||||
expect(post_status0.reload.order).to eq(0)
|
||||
expect(post_status1.reload.order).to eq(3)
|
||||
expect(post_status3.reload.order).to eq(2)
|
||||
expect(post_status2.reload.order).to eq(1)
|
||||
expect(post_status4.reload.order).to eq(4)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user