Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend inspection model to store an elimination method text code #827

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/elimination_method.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- encoding : utf-8 -*-
class EliminationMethod < ActiveRecord::Base
belongs_to :breeding_site

has_many :organization_elimination_method, class_name: "OrganizationEliminationMethod"
#----------------------------------------------------------------------------

validates :points, :presence => true
Expand Down
1 change: 1 addition & 0 deletions app/models/inspection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ module Types
belongs_to :eliminator, :class_name => "User"
belongs_to :spreadsheet, :foreign_key => "csv_id"

belongs_to :organization_elimination_method, class_name: "OrganizationEliminationMethod", foreign_key: "organization_elimination_method_id"

#----------------------------------------------------------------------------
# Validations
Expand Down
2 changes: 1 addition & 1 deletion app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ class Organization < ActiveRecord::Base
has_many :memberships
has_many :users, :through => :memberships
has_many :teams

has_many :organization_elimination_method, class_name: "OrganizationEliminationMethod"
validates_presence_of :name
end
7 changes: 7 additions & 0 deletions app/models/organization_elimination_method.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class OrganizationEliminationMethod < ActiveRecord::Base
self.table_name = "organization_elimination_methods"
belongs_to :elimination_method
belongs_to :organization
validates_presence_of :elimination_method_id, :organization_id
attr_accessible :elimination_method, :organization_id, :code, :description
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddOrganizationEliminationMethodToInspections < ActiveRecord::Migration
def change
add_reference :inspections, :organization_elimination_method, index: false
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateOrganizationEliminationMethods < ActiveRecord::Migration
def change
create_table :organization_elimination_methods do |t|
t.integer :elimination_method_id
t.integer :organization_id
t.string :code
t.string :description
end
end
end
22 changes: 20 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180312171712) do
ActiveRecord::Schema.define(version: 20180416032739) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -204,7 +204,7 @@
t.integer "visit_id"
t.integer "report_id"
t.integer "identification_type"
t.integer "position", default: 0
t.integer "position", default: 0
t.integer "csv_id"
t.string "source"
t.datetime "last_synced_at"
Expand Down Expand Up @@ -233,8 +233,12 @@
t.string "csv_uuid"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "organization_breeding_site_id"
t.integer "organization_elimination_method_id"
end

add_index "inspections", ["organization_breeding_site_id"], name: "index_inspections_on_organization_breeding_site_id_id", using: :btree

create_table "likes", force: :cascade do |t|
t.integer "user_id"
t.integer "likeable_id"
Expand Down Expand Up @@ -333,13 +337,27 @@
t.boolean "read", default: false
end

create_table "organization_elimination_methods", force: :cascade do |t|
t.integer "elimination_method_id"
t.integer "organization_id"
t.string "code"
t.string "description"
end

create_table "organizations", force: :cascade do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.jsonb "breeding_sites_codes"
end

create_table "organizations_breeding_sites", force: :cascade do |t|
t.integer "organization_id"
t.integer "breeding_site_id"
t.text "description", default: ""
t.string "code"
end

create_table "posts", force: :cascade do |t|
t.integer "user_id"
t.string "title", limit: 255
Expand Down
5 changes: 4 additions & 1 deletion spec/factories.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- encoding : utf-8 -*-
require 'rack/test'

FactoryGirl.define do
FactoryGirl.define do factory :organization_elimination_method do

end

factory :organization do
name "SSI"
end
Expand Down
5 changes: 5 additions & 0 deletions spec/models/organization_elimination_method_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe OrganizationEliminationMethod, type: :model do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agregale esto @ricpar11 antes de hacer merge. Y aseguremos que funcione igual cuando no hay códigos de eliminación en la organizacion

pending "add some examples to (or delete) #{__FILE__}"
end