Add specs for model facebook_page (#346)
This commit is contained in:
parent
ff5c26a388
commit
3a1c0aef07
5 changed files with 33 additions and 3 deletions
|
@ -14,7 +14,8 @@
|
|||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_channel_facebook_pages_on_page_id (page_id)
|
||||
# index_channel_facebook_pages_on_page_id (page_id)
|
||||
# index_channel_facebook_pages_on_page_id_and_account_id (page_id,account_id) UNIQUE
|
||||
#
|
||||
|
||||
module Channel
|
||||
|
@ -22,7 +23,7 @@ module Channel
|
|||
self.table_name = 'channel_facebook_pages'
|
||||
|
||||
validates :account_id, presence: true
|
||||
validates_uniqueness_of :page_id, scope: :account_id
|
||||
validates :page_id, uniqueness: { scope: :account_id }
|
||||
mount_uploader :avatar, AvatarUploader
|
||||
belongs_to :account
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddIndexUniqueChannelFacebookPageIdAccountId < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_index :channel_facebook_pages, [:page_id, :account_id], unique: true
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2019_12_02_173004) do
|
||||
ActiveRecord::Schema.define(version: 2019_12_04_192301) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -52,6 +52,7 @@ ActiveRecord::Schema.define(version: 2019_12_02_173004) do
|
|||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "avatar"
|
||||
t.index ["page_id", "account_id"], name: "index_channel_facebook_pages_on_page_id_and_account_id", unique: true
|
||||
t.index ["page_id"], name: "index_channel_facebook_pages_on_page_id"
|
||||
end
|
||||
|
||||
|
|
11
spec/factories/channel/facebook_pages.rb
Normal file
11
spec/factories/channel/facebook_pages.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :channel_facebook_page, class: Channel::FacebookPage do
|
||||
name { Faker::Name.name }
|
||||
page_access_token { SecureRandom.uuid }
|
||||
user_access_token { SecureRandom.uuid }
|
||||
page_id { SecureRandom.uuid }
|
||||
account
|
||||
end
|
||||
end
|
12
spec/models/channel/facebook_page_spec.rb
Normal file
12
spec/models/channel/facebook_page_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Channel::FacebookPage do
|
||||
before { create(:channel_facebook_page) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:account_id) }
|
||||
it { is_expected.to validate_uniqueness_of(:page_id).scoped_to(:account_id) }
|
||||
it { is_expected.to belong_to(:account) }
|
||||
it { is_expected.to have_one(:inbox).dependent(:destroy) }
|
||||
end
|
Loading…
Reference in a new issue