diff --git a/app/models/cerfa.rb b/app/models/cerfa.rb new file mode 100644 index 000000000..0b7404fe3 --- /dev/null +++ b/app/models/cerfa.rb @@ -0,0 +1,5 @@ +class Cerfa < ActiveRecord::Base + belongs_to :dossier + + mount_uploader :content, CerfaUploader +end \ No newline at end of file diff --git a/app/models/dossier.rb b/app/models/dossier.rb index b64f480a5..3c5ee6b18 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -1,6 +1,7 @@ class Dossier < ActiveRecord::Base has_one :etablissement has_one :entreprise + has_one :cerfa has_many :pieces_jointes belongs_to :formulaire has_many :commentaires diff --git a/app/uploaders/cerfa_uploader.rb b/app/uploaders/cerfa_uploader.rb new file mode 100644 index 000000000..9222caafa --- /dev/null +++ b/app/uploaders/cerfa_uploader.rb @@ -0,0 +1,51 @@ +# encoding: utf-8 + +class CerfaUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + # include CarrierWave::RMagick + # include CarrierWave::MiniMagick + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url + # # For Rails 3.1+ asset pipeline compatibility: + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process :scale => [200, 300] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + # version :thumb do + # process :resize_to_fit => [50, 50] + # end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + def extension_white_list + %w(pdf) + end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end diff --git a/db/migrate/20150818113123_create_cerfas.rb b/db/migrate/20150818113123_create_cerfas.rb new file mode 100644 index 000000000..301204947 --- /dev/null +++ b/db/migrate/20150818113123_create_cerfas.rb @@ -0,0 +1,9 @@ +class CreateCerfas < ActiveRecord::Migration + def change + create_table :cerfas do |t| + t.string :content + t.references :dossier, index: true + end + add_foreign_key :cerfas, :dossiers + end +end diff --git a/db/schema.rb b/db/schema.rb index 518b6ea6e..08eabf779 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,11 +11,18 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150814124735) do +ActiveRecord::Schema.define(version: 20150818113123) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "cerfas", force: :cascade do |t| + t.string "content" + t.integer "dossier_id" + end + + add_index "cerfas", ["dossier_id"], name: "index_cerfas_on_dossier_id", using: :btree + create_table "commentaires", force: :cascade do |t| t.string "email" t.datetime "created_at", null: false @@ -162,5 +169,6 @@ ActiveRecord::Schema.define(version: 20150814124735) do add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree + add_foreign_key "cerfas", "dossiers" add_foreign_key "commentaires", "dossiers" end diff --git a/spec/models/cerfa_spec.rb b/spec/models/cerfa_spec.rb new file mode 100644 index 000000000..ca4d8d45c --- /dev/null +++ b/spec/models/cerfa_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe Cerfa do + describe 'database columns' do + it { is_expected.to have_db_column(:content)} + end + + describe 'associations' do + it { is_expected.to belong_to(:dossier) } + end + +end \ No newline at end of file diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index cc115e5d6..2ce408591 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -21,6 +21,7 @@ describe Dossier do it { is_expected.to belong_to(:formulaire) } it { is_expected.to have_many(:pieces_jointes) } it { is_expected.to have_many(:commentaires) } + it { is_expected.to have_one(:cerfa) } it { is_expected.to have_one(:etablissement) } it { is_expected.to have_one(:entreprise) } end