add cerfa model

This commit is contained in:
Tanguy PATTE 2015-08-18 13:52:00 +02:00
parent 0eb699d6b9
commit 8273438910
7 changed files with 88 additions and 1 deletions

5
app/models/cerfa.rb Normal file
View file

@ -0,0 +1,5 @@
class Cerfa < ActiveRecord::Base
belongs_to :dossier
mount_uploader :content, CerfaUploader
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

12
spec/models/cerfa_spec.rb Normal file
View file

@ -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

View file

@ -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