adds Valuator

This commit is contained in:
Juanjo Bazán
2016-02-17 17:46:59 +01:00
parent 9561259800
commit 009733a43b
6 changed files with 49 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ class User < ActiveRecord::Base
has_one :administrator has_one :administrator
has_one :moderator has_one :moderator
has_one :valuator
has_one :organization has_one :organization
has_one :lock has_one :lock
has_many :flags has_many :flags
@@ -92,6 +93,10 @@ class User < ActiveRecord::Base
moderator.present? moderator.present?
end end
def valuator?
valuator.present?
end
def organization? def organization?
organization.present? organization.present?
end end

6
app/models/valuator.rb Normal file
View File

@@ -0,0 +1,6 @@
class Valuator < ActiveRecord::Base
belongs_to :user, touch: true
delegate :name, :email, to: :user
validates :user_id, presence: true, uniqueness: true
end

View File

@@ -0,0 +1,7 @@
class CreateValuators < ActiveRecord::Migration
def change
create_table :valuators do |t|
t.belongs_to :user, index: true, foreign_key: true
end
end
end

View File

@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160216121051) do ActiveRecord::Schema.define(version: 20160217101004) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -415,6 +415,18 @@ ActiveRecord::Schema.define(version: 20160216121051) do
add_index "users", ["hidden_at"], name: "index_users_on_hidden_at", using: :btree add_index "users", ["hidden_at"], name: "index_users_on_hidden_at", using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
create_table "validators", force: :cascade do |t|
t.integer "user_id"
end
add_index "validators", ["user_id"], name: "index_validators_on_user_id", using: :btree
create_table "valuators", force: :cascade do |t|
t.integer "user_id"
end
add_index "valuators", ["user_id"], name: "index_valuators_on_user_id", using: :btree
create_table "verified_users", force: :cascade do |t| create_table "verified_users", force: :cascade do |t|
t.string "document_number" t.string "document_number"
t.string "document_type" t.string "document_type"
@@ -484,4 +496,6 @@ ActiveRecord::Schema.define(version: 20160216121051) do
add_foreign_key "moderators", "users" add_foreign_key "moderators", "users"
add_foreign_key "notifications", "users" add_foreign_key "notifications", "users"
add_foreign_key "organizations", "users" add_foreign_key "organizations", "users"
add_foreign_key "validators", "users"
add_foreign_key "valuators", "users"
end end

View File

@@ -1,5 +1,4 @@
FactoryGirl.define do FactoryGirl.define do
sequence(:document_number) { |n| "#{n.to_s.rjust(8, '0')}X" } sequence(:document_number) { |n| "#{n.to_s.rjust(8, '0')}X" }
factory :user do factory :user do
@@ -251,6 +250,10 @@ FactoryGirl.define do
user user
end end
factory :valuator do
user
end
factory :organization do factory :organization do
user user
responsible_name "Johnny Utah" responsible_name "Johnny Utah"

View File

@@ -109,6 +109,18 @@ describe User do
end end
end end
describe "valuator?" do
it "is false when the user is not a valuator" do
expect(subject.valuator?).to be false
end
it "is true when the user is a valuator" do
subject.save
create(:valuator, user: subject)
expect(subject.valuator?).to be true
end
end
describe "organization?" do describe "organization?" do
it "is false when the user is not an organization" do it "is false when the user is not an organization" do
expect(subject.organization?).to be false expect(subject.organization?).to be false
@@ -291,7 +303,6 @@ describe User do
expect { user.organization.verify } expect { user.organization.verify }
.to change { user.reload.updated_at} .to change { user.reload.updated_at}
end end
end end
describe "document_number" do describe "document_number" do