Merge pull request #500 from sgmap/add-published-at

Add published at
This commit is contained in:
gregoirenovel 2017-06-27 13:59:03 +02:00 committed by GitHub
commit 47e50e3731
4 changed files with 21 additions and 14 deletions

View file

@ -112,7 +112,7 @@ class Procedure < ActiveRecord::Base
end
def publish!(path)
self.update_attributes!({published: true, archived: false})
self.update_attributes!({ published: true, archived: false, published_at: Time.now })
ProcedurePath.create!(path: path, procedure: self, administrateur: self.administrateur)
end

View file

@ -0,0 +1,5 @@
class AddPublishedAtToProcedure < ActiveRecord::Migration[5.0]
def change
add_column :procedures, :published_at, :datetime
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170601123221) do
ActiveRecord::Schema.define(version: 20170627091953) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -381,7 +381,8 @@ ActiveRecord::Schema.define(version: 20170601123221) do
t.string "lien_notice"
t.boolean "for_individual", default: false
t.boolean "individual_with_siret", default: false
t.date "auto_archive_on"
t.datetime "auto_archive_on"
t.datetime "published_at"
end
create_table "quartier_prioritaires", force: :cascade do |t|
@ -500,4 +501,5 @@ ActiveRecord::Schema.define(version: 20170601123221) do
LEFT JOIN individuals ON ((individuals.dossier_id = dossiers.id)))
LEFT JOIN pieces_justificatives ON ((pieces_justificatives.dossier_id = dossiers.id)));
SQL
end

View file

@ -219,20 +219,20 @@ describe Procedure do
end
end
describe 'publish' do
let(:procedure) { create(:procedure, :published) }
let(:procedure_path) { ProcedurePath.find(procedure.procedure_path.id) }
describe '#publish!' do
let(:procedure) { create(:procedure) }
it 'is available from a valid path' do
expect(procedure.path).to match(/fake_path/)
expect(procedure.published).to be_truthy
before do
procedure.publish!("example-path")
Timecop.freeze(Time.now)
end
it 'is correctly set in ProcedurePath table' do
expect(ProcedurePath.where(path: procedure.path).count).to eq(1)
expect(procedure_path.procedure_id).to eq(procedure.id)
expect(procedure_path.administrateur_id).to eq(procedure.administrateur_id)
end
it { expect(procedure.published).to eq(true) }
it { expect(procedure.archived).to eq(false) }
it { expect(procedure.published_at).to eq(Time.now) }
it { expect(ProcedurePath.find_by_path("example-path")).to be }
it { expect(ProcedurePath.find_by_path("example-path").procedure).to eq(procedure) }
it { expect(ProcedurePath.find_by_path("example-path").administrateur).to eq(procedure.administrateur) }
end
describe 'archive' do