adds Valuator
This commit is contained in:
@@ -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
6
app/models/valuator.rb
Normal 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
|
||||||
7
db/migrate/20160217101004_create_valuators.rb
Normal file
7
db/migrate/20160217101004_create_valuators.rb
Normal 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
|
||||||
16
db/schema.rb
16
db/schema.rb
@@ -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
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user