From 938b15fc46878044d6f16c8db7142bb2eac7d4a8 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 7 Dec 2018 00:19:41 +0500 Subject: [PATCH] Add model MembershipPool --- app/models/membership_pool.rb | 5 +++++ .../20181206190602_create_membership_pools.rb | 10 ++++++++++ db/schema.rb | 8 +++++++- db/seeds.rb | 15 ++++++++------- factories/membership_pools.rb | 7 +++++++ spec/models/membership_pool_spec.rb | 9 +++++++++ 6 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 app/models/membership_pool.rb create mode 100644 db/migrate/20181206190602_create_membership_pools.rb create mode 100644 factories/membership_pools.rb create mode 100644 spec/models/membership_pool_spec.rb diff --git a/app/models/membership_pool.rb b/app/models/membership_pool.rb new file mode 100644 index 0000000..a4f0cda --- /dev/null +++ b/app/models/membership_pool.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class MembershipPool < ApplicationRecord + validates :name, presence: true +end diff --git a/db/migrate/20181206190602_create_membership_pools.rb b/db/migrate/20181206190602_create_membership_pools.rb new file mode 100644 index 0000000..739302a --- /dev/null +++ b/db/migrate/20181206190602_create_membership_pools.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class CreateMembershipPools < ActiveRecord::Migration[5.2] + def change + create_table :membership_pools do |t| + t.timestamps null: false + t.string :name, null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 3dd9795..7e1d4b8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_12_06_014718) do +ActiveRecord::Schema.define(version: 2018_12_06_190602) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -77,6 +77,12 @@ ActiveRecord::Schema.define(version: 2018_12_06_014718) do t.index ["country_state_id"], name: "index_membership_applications_on_country_state_id" end + create_table "membership_pools", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "name", null: false + end + create_table "passport_confirmations", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false diff --git a/db/seeds.rb b/db/seeds.rb index f6a2af1..cc4b733 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -10,10 +10,11 @@ country_state_names.each do |name| CountryState.create! name: name end -admin_account = Account.create! -admin_account.create_user!( - email: Rails.application.credentials.initial_superuser_email, - password: Rails.application.credentials.initial_superuser_password, - confirmed_at: Time.zone.now, -) -admin_account.add_role :superuser +User.where(email: Rails.application.credentials.initial_superuser_email) + .first_or_create! do |new_user| + new_user.account = Account.create! + new_user.password = Rails.application.credentials.initial_superuser_password + new_user.confirmed_at = Time.zone.now +end.account.add_role :superuser + +MembershipPool.create! name: 'Все заявления' unless MembershipPool.any? diff --git a/factories/membership_pools.rb b/factories/membership_pools.rb new file mode 100644 index 0000000..512e43f --- /dev/null +++ b/factories/membership_pools.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :membership_pool do + name { Faker::Lorem.sentence[0...-1] } + end +end diff --git a/spec/models/membership_pool_spec.rb b/spec/models/membership_pool_spec.rb new file mode 100644 index 0000000..e54b4d4 --- /dev/null +++ b/spec/models/membership_pool_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe MembershipPool do + subject { create :membership_pool } + + it { is_expected.to validate_presence_of :name } +end