Merge pull request #1926 from tchak/add-aasm-state

Add aasm state
This commit is contained in:
Paul Chavard 2018-05-17 14:07:51 +01:00 committed by GitHub
commit 684d57bd49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 4 deletions

View file

@ -99,6 +99,8 @@ gem 'sanitize-url'
gem 'flipflop'
gem 'aasm'
# Cron jobs
gem 'delayed_job_active_record'
gem "daemons"

View file

@ -29,6 +29,8 @@ GEM
remote: https://rubygems.org/
specs:
CFPropertyList (2.3.6)
aasm (4.12.3)
concurrent-ruby (~> 1.0)
actioncable (5.2.0)
actionpack (= 5.2.0)
nio4r (~> 2.0)
@ -779,6 +781,7 @@ PLATFORMS
ruby
DEPENDENCIES
aasm
active_model_serializers
administrate
apipie-rails

View file

@ -63,7 +63,7 @@ class Procedure < ApplicationRecord
def hide!
now = DateTime.now
self.update(hidden_at: now)
self.update(hidden_at: now, aasm_state: :hidden)
self.dossiers.update_all(hidden_at: now)
end
@ -154,7 +154,7 @@ class Procedure < ApplicationRecord
def publish!(path)
now = Time.now
self.update!({ test_started_at: now, published_at: now, archived_at: nil })
self.update!({ test_started_at: now, published_at: now, archived_at: nil, aasm_state: :publiee })
ProcedurePath.create!(path: path, procedure: self, administrateur: self.administrateur)
end
@ -163,7 +163,7 @@ class Procedure < ApplicationRecord
end
def archive
self.update!(archived_at: Time.now)
self.update!(archived_at: Time.now, aasm_state: :archivee)
end
def archivee?

View file

@ -0,0 +1,5 @@
class AddAasmStateToProcedures < ActiveRecord::Migration[5.2]
def change
add_column :procedures, :aasm_state, :string, index: true, default: :brouillon
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: 2018_05_02_092852) do
ActiveRecord::Schema.define(version: 2018_05_15_135415) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -465,6 +465,7 @@ ActiveRecord::Schema.define(version: 2018_05_02_092852) do
t.boolean "cloned_from_library", default: false
t.bigint "parent_procedure_id"
t.datetime "test_started_at"
t.string "aasm_state", default: "brouillon"
t.index ["hidden_at"], name: "index_procedures_on_hidden_at"
t.index ["parent_procedure_id"], name: "index_procedures_on_parent_procedure_id"
end

View file

@ -0,0 +1,8 @@
namespace :'2018_05_15_add_aasm_state_to_procedure' do
task set: :environment do
Procedure.archivees.update_all(aasm_state: :archivee)
Procedure.publiees.update_all(aasm_state: :publiee)
Procedure.brouillons.update_all(aasm_state: :brouillon)
Procedure.unscoped.where.not(hidden_at: nil).update_all(aasm_state: :hidden)
end
end