Create sdg manager

This commit is contained in:
taitus
2020-11-25 12:02:19 +01:00
committed by Javi Martín
parent 599332f26e
commit cd7185f317
6 changed files with 44 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
class SDG::Manager < ApplicationRecord
belongs_to :user, touch: true
delegate :name, :email, to: :user
validates :user_id, presence: true, uniqueness: true
end

View File

@@ -15,6 +15,7 @@ class User < ApplicationRecord
has_one :moderator
has_one :valuator
has_one :manager
has_one :sdg_manager, class_name: "SDG::Manager", dependent: :destroy
has_one :poll_officer, class_name: "Poll::Officer"
has_one :organization
has_one :lock
@@ -197,6 +198,10 @@ class User < ApplicationRecord
manager.present?
end
def sdg_manager?
sdg_manager.present?
end
def poll_officer?
poll_officer.present?
end

View File

@@ -0,0 +1,8 @@
class CreateSDGManager < ActiveRecord::Migration[5.2]
def change
create_table :sdg_managers do |t|
t.belongs_to :user, foreign_key: true, index: { unique: true }
t.timestamps
end
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_11_23_124006) do
ActiveRecord::Schema.define(version: 2020_11_24_145559) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
@@ -1324,6 +1324,13 @@ ActiveRecord::Schema.define(version: 2020_11_23_124006) do
t.index ["target_id"], name: "index_sdg_local_targets_on_target_id"
end
create_table "sdg_managers", force: :cascade do |t|
t.bigint "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_sdg_managers_on_user_id", unique: true
end
create_table "sdg_relations", force: :cascade do |t|
t.string "related_sdg_type"
t.bigint "related_sdg_id"
@@ -1694,6 +1701,7 @@ ActiveRecord::Schema.define(version: 2020_11_23_124006) do
add_foreign_key "proposals", "communities"
add_foreign_key "related_content_scores", "related_contents"
add_foreign_key "related_content_scores", "users"
add_foreign_key "sdg_managers", "users"
add_foreign_key "users", "geozones"
add_foreign_key "valuators", "users"
end

View File

@@ -106,6 +106,10 @@ FactoryBot.define do
user
end
factory :sdg_manager, class: "SDG::Manager" do
user
end
factory :poll_officer, class: "Poll::Officer" do
user { association(:user, username: name) }

View File

@@ -189,6 +189,18 @@ describe User do
end
end
describe "sdg_manager?" do
it "is false when the user is not a sdg manager" do
expect(subject.sdg_manager?).to be false
end
it "is true when the user is a sdg manager" do
subject.save!
create(:sdg_manager, user: subject)
expect(subject.sdg_manager?).to be true
end
end
describe "poll_officer?" do
it "is false when the user is not a poll officer" do
expect(subject.poll_officer?).to be false