🚨Fix Rubocop lint errors

This commit is contained in:
Pranav Raj S
2019-10-20 14:17:26 +05:30
committed by GitHub
parent dd018f3682
commit 94c6d6db6f
124 changed files with 774 additions and 914 deletions

View File

@@ -2,11 +2,11 @@ class DeviseTokenAuthCreateUsers < ActiveRecord::Migration[5.0]
def change
create_table(:users) do |t|
## Required
t.string :provider, :null => false, :default => "email"
t.string :uid, :null => false, :default => ""
t.string :provider, null: false, default: 'email'
t.string :uid, null: false, default: ''
## Database authenticatable
t.string :encrypted_password, :null => false, :default => ""
t.string :encrypted_password, null: false, default: ''
## Recoverable
t.string :reset_password_token
@@ -16,7 +16,7 @@ class DeviseTokenAuthCreateUsers < ActiveRecord::Migration[5.0]
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0, :null => false
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
@@ -41,13 +41,13 @@ class DeviseTokenAuthCreateUsers < ActiveRecord::Migration[5.0]
## Tokens
t.json :tokens
t.integer :account_id, :null => false
t.integer :account_id, null: false
t.timestamps
end
add_index :users, :email
add_index :users, [:uid, :provider], :unique => true
add_index :users, :reset_password_token, :unique => true
add_index :users, [:uid, :provider], unique: true
add_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token, :unique => true
# add_index :users, :unlock_token, :unique => true
end

View File

@@ -1,5 +1,5 @@
class ChangeContactToBigint < ActiveRecord::Migration[5.0]
def change
change_column :contacts, :id , :bigint
change_column :contacts, :id, :bigint
end
end

View File

@@ -3,8 +3,6 @@
# work properly
class ChangeCollationForTagNames < ActiveRecord::Migration[5.0]
def up
if ActsAsTaggableOn::Utils.using_mysql?
execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
end
execute('ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;') if ActsAsTaggableOn::Utils.using_mysql?
end
end

View File

@@ -1,7 +1,7 @@
class Addallnametousers < ActiveRecord::Migration[5.0]
def change
User.all.each do |u|
u.name = "Subash"
u.name = 'Subash'
u.save!
end
end

View File

@@ -1,6 +1,6 @@
class Notnullableusers < ActiveRecord::Migration[5.0]
def change
change_column :users, :name, :string, :null => false
change_column :users, :account_id, :integer, :null => false
change_column :users, :name, :string, null: false
change_column :users, :account_id, :integer, null: false
end
end

View File

@@ -1,7 +1,7 @@
class AddDisplayId < ActiveRecord::Migration[5.0]
def change
Conversation.all.each do |conversation|
conversation.display_id = Conversation.where(account_id: conversation.account_id).maximum("display_id").to_i + 1
conversation.display_id = Conversation.where(account_id: conversation.account_id).maximum('display_id').to_i + 1
conversation.save!
end
end

View File

@@ -1,9 +1,7 @@
class CreateTriggerConversationsInsert < ActiveRecord::Migration[5.0]
def up
change_column :conversations, :display_id, :integer, :null => false
change_column :conversations, :display_id, :integer, null: false
end
def down
end
def down; end
end

View File

@@ -1,6 +1,6 @@
class AddUniqueDisplayId < ActiveRecord::Migration[5.0]
def change
remove_index(:conversations, :name => 'index_conversations_on_account_id_and_display_id')
add_index :conversations, [:account_id, :display_id], :unique => true
remove_index(:conversations, name: 'index_conversations_on_account_id_and_display_id')
add_index :conversations, [:account_id, :display_id], unique: true
end
end

View File

@@ -1,5 +1,5 @@
class ChangeLastSeenAtToDateTime < ActiveRecord::Migration[5.0]
def change
change_column :conversations, :last_seen_at , :datetime
change_column :conversations, :last_seen_at, :datetime
end
end

View File

@@ -3,8 +3,12 @@ class CreateExtensionForFile < ActiveRecord::Migration[5.0]
def change
add_column :attachments, :extension, :string, default: nil
Attachment.find_each do |attachment|
if attachment.external_url and attachment.file_type != fallback
attachment.extension = Pathname.new(URI(attachment.external_url).path).extname rescue nil
if attachment.external_url && (attachment.file_type != fallback)
attachment.extension = begin
Pathname.new(URI(attachment.external_url).path).extname
rescue StandardError
nil
end
attachment.save!
end
end

View File

@@ -2,23 +2,23 @@ class AddPicToInboxMigration < ActiveRecord::Migration[5.0]
def change
FacebookPage.find_each do |inbox|
begin
url = "http://graph.facebook.com/"<< inbox.page_id << "/picture?type=large"
url = 'http://graph.facebook.com/' << inbox.page_id << '/picture?type=large'
uri = URI.parse(url)
tries = 3
begin
response = uri.open(redirect: false)
rescue OpenURI::HTTPRedirect => redirect
uri = redirect.uri # assigned from the "Location" response header
retry if (tries -= 1) > 0
raise
end
begin
response = uri.open(redirect: false)
rescue OpenURI::HTTPRedirect => e
uri = e.uri # assigned from the "Location" response header
retry if (tries -= 1) > 0
raise
end
pic_url = response.base_uri.to_s
puts pic_url.inspect
rescue => e
rescue StandardError => e
pic_url = nil
end
inbox.remote_avatar_url = pic_url
inbox.save!
inbox.remote_avatar_url = pic_url
inbox.save!
end
end
end

View File

@@ -1,7 +1,7 @@
class RoundRobin < ActiveRecord::Migration[5.0]
def change
InboxMember.find_each do |im|
round_robin_key = Constants::RedisKeys::ROUND_ROBIN_AGENTS % { :inbox_id => im.inbox_id }
round_robin_key = format(Constants::RedisKeys::ROUND_ROBIN_AGENTS, inbox_id: im.inbox_id)
Redis::Alfred.lpush(round_robin_key, im.user_id)
end
end

View File

@@ -3,7 +3,7 @@ class RenameChannelAttributeNameInModels < ActiveRecord::Migration[6.1]
rename_column :users, :channel, :pubsub_token
rename_column :contacts, :chat_channel, :pubsub_token
add_index :users, :pubsub_token, unique: true
add_index :contacts, :pubsub_token, unique: true
add_index :users, :pubsub_token, unique: true
add_index :contacts, :pubsub_token, unique: true
end
end

View File

@@ -10,209 +10,208 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_10_16_211109) do
ActiveRecord::Schema.define(version: 20_191_016_211_109) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension 'plpgsql'
create_table "accounts", id: :serial, force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
create_table 'accounts', id: :serial, force: :cascade do |t|
t.string 'name'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
end
create_table "attachments", id: :serial, force: :cascade do |t|
t.string "file"
t.integer "file_type", default: 0
t.string "external_url"
t.float "coordinates_lat", default: 0.0
t.float "coordinates_long", default: 0.0
t.integer "message_id", null: false
t.integer "account_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "fallback_title"
t.string "extension"
create_table 'attachments', id: :serial, force: :cascade do |t|
t.string 'file'
t.integer 'file_type', default: 0
t.string 'external_url'
t.float 'coordinates_lat', default: 0.0
t.float 'coordinates_long', default: 0.0
t.integer 'message_id', null: false
t.integer 'account_id', null: false
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.string 'fallback_title'
t.string 'extension'
end
create_table "canned_responses", id: :serial, force: :cascade do |t|
t.integer "account_id", null: false
t.string "short_code"
t.text "content"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
create_table 'canned_responses', id: :serial, force: :cascade do |t|
t.integer 'account_id', null: false
t.string 'short_code'
t.text 'content'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
end
create_table "channel_widgets", id: :serial, force: :cascade do |t|
t.string "website_name"
t.string "website_url"
t.integer "account_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
create_table 'channel_widgets', id: :serial, force: :cascade do |t|
t.string 'website_name'
t.string 'website_url'
t.integer 'account_id'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
end
create_table "channels", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
create_table 'channels', force: :cascade do |t|
t.string 'name'
t.datetime 'created_at', precision: 6, null: false
t.datetime 'updated_at', precision: 6, null: false
end
create_table "contacts", id: :serial, force: :cascade do |t|
t.string "name"
t.string "email"
t.string "phone_number"
t.integer "account_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "inbox_id", null: false
t.bigserial "source_id", null: false
t.string "avatar"
t.string "pubsub_token"
t.index ["account_id"], name: "index_contacts_on_account_id"
t.index ["pubsub_token"], name: "index_contacts_on_pubsub_token", unique: true
create_table 'contacts', id: :serial, force: :cascade do |t|
t.string 'name'
t.string 'email'
t.string 'phone_number'
t.integer 'account_id', null: false
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.integer 'inbox_id', null: false
t.bigserial 'source_id', null: false
t.string 'avatar'
t.string 'pubsub_token'
t.index ['account_id'], name: 'index_contacts_on_account_id'
t.index ['pubsub_token'], name: 'index_contacts_on_pubsub_token', unique: true
end
create_table "conversations", id: :serial, force: :cascade do |t|
t.integer "account_id", null: false
t.integer "inbox_id", null: false
t.integer "status", default: 0, null: false
t.integer "assignee_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.bigint "sender_id"
t.integer "display_id", null: false
t.datetime "user_last_seen_at"
t.datetime "agent_last_seen_at"
t.boolean "locked", default: false
t.index ["account_id", "display_id"], name: "index_conversations_on_account_id_and_display_id", unique: true
t.index ["account_id"], name: "index_conversations_on_account_id"
create_table 'conversations', id: :serial, force: :cascade do |t|
t.integer 'account_id', null: false
t.integer 'inbox_id', null: false
t.integer 'status', default: 0, null: false
t.integer 'assignee_id'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.bigint 'sender_id'
t.integer 'display_id', null: false
t.datetime 'user_last_seen_at'
t.datetime 'agent_last_seen_at'
t.boolean 'locked', default: false
t.index %w[account_id display_id], name: 'index_conversations_on_account_id_and_display_id', unique: true
t.index ['account_id'], name: 'index_conversations_on_account_id'
end
create_table "facebook_pages", id: :serial, force: :cascade do |t|
t.string "name", null: false
t.string "page_id", null: false
t.string "user_access_token", null: false
t.string "page_access_token", null: false
t.integer "account_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "avatar"
t.index ["page_id"], name: "index_facebook_pages_on_page_id"
create_table 'facebook_pages', id: :serial, force: :cascade do |t|
t.string 'name', null: false
t.string 'page_id', null: false
t.string 'user_access_token', null: false
t.string 'page_access_token', null: false
t.integer 'account_id', null: false
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.string 'avatar'
t.index ['page_id'], name: 'index_facebook_pages_on_page_id'
end
create_table "inbox_members", id: :serial, force: :cascade do |t|
t.integer "user_id", null: false
t.integer "inbox_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["inbox_id"], name: "index_inbox_members_on_inbox_id"
create_table 'inbox_members', id: :serial, force: :cascade do |t|
t.integer 'user_id', null: false
t.integer 'inbox_id', null: false
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.index ['inbox_id'], name: 'index_inbox_members_on_inbox_id'
end
create_table "inboxes", id: :serial, force: :cascade do |t|
t.integer "channel_id", null: false
t.integer "account_id", null: false
t.string "name", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "channel_type"
t.index ["account_id"], name: "index_inboxes_on_account_id"
create_table 'inboxes', id: :serial, force: :cascade do |t|
t.integer 'channel_id', null: false
t.integer 'account_id', null: false
t.string 'name', null: false
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.string 'channel_type'
t.index ['account_id'], name: 'index_inboxes_on_account_id'
end
create_table "messages", id: :serial, force: :cascade do |t|
t.text "content"
t.integer "account_id", null: false
t.integer "inbox_id", null: false
t.integer "conversation_id", null: false
t.integer "message_type", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "private", default: false
t.integer "user_id"
t.integer "status", default: 0
t.string "fb_id"
t.index ["conversation_id"], name: "index_messages_on_conversation_id"
create_table 'messages', id: :serial, force: :cascade do |t|
t.text 'content'
t.integer 'account_id', null: false
t.integer 'inbox_id', null: false
t.integer 'conversation_id', null: false
t.integer 'message_type', null: false
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.boolean 'private', default: false
t.integer 'user_id'
t.integer 'status', default: 0
t.string 'fb_id'
t.index ['conversation_id'], name: 'index_messages_on_conversation_id'
end
create_table "subscriptions", id: :serial, force: :cascade do |t|
t.string "pricing_version"
t.integer "account_id"
t.datetime "expiry"
t.string "billing_plan", default: "trial"
t.string "stripe_customer_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "state", default: 0
t.boolean "payment_source_added", default: false
create_table 'subscriptions', id: :serial, force: :cascade do |t|
t.string 'pricing_version'
t.integer 'account_id'
t.datetime 'expiry'
t.string 'billing_plan', default: 'trial'
t.string 'stripe_customer_id'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.integer 'state', default: 0
t.boolean 'payment_source_added', default: false
end
create_table "taggings", id: :serial, force: :cascade do |t|
t.integer "tag_id"
t.string "taggable_type"
t.integer "taggable_id"
t.string "tagger_type"
t.integer "tagger_id"
t.string "context", limit: 128
t.datetime "created_at"
t.index ["context"], name: "index_taggings_on_context"
t.index ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true
t.index ["tag_id"], name: "index_taggings_on_tag_id"
t.index ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context"
t.index ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy"
t.index ["taggable_id"], name: "index_taggings_on_taggable_id"
t.index ["taggable_type", "taggable_id"], name: "index_taggings_on_taggable_type_and_taggable_id"
t.index ["taggable_type"], name: "index_taggings_on_taggable_type"
t.index ["tagger_id", "tagger_type"], name: "index_taggings_on_tagger_id_and_tagger_type"
t.index ["tagger_id"], name: "index_taggings_on_tagger_id"
t.index ["tagger_type", "tagger_id"], name: "index_taggings_on_tagger_type_and_tagger_id"
create_table 'taggings', id: :serial, force: :cascade do |t|
t.integer 'tag_id'
t.string 'taggable_type'
t.integer 'taggable_id'
t.string 'tagger_type'
t.integer 'tagger_id'
t.string 'context', limit: 128
t.datetime 'created_at'
t.index ['context'], name: 'index_taggings_on_context'
t.index %w[tag_id taggable_id taggable_type context tagger_id tagger_type], name: 'taggings_idx', unique: true
t.index ['tag_id'], name: 'index_taggings_on_tag_id'
t.index %w[taggable_id taggable_type context], name: 'index_taggings_on_taggable_id_and_taggable_type_and_context'
t.index %w[taggable_id taggable_type tagger_id context], name: 'taggings_idy'
t.index ['taggable_id'], name: 'index_taggings_on_taggable_id'
t.index %w[taggable_type taggable_id], name: 'index_taggings_on_taggable_type_and_taggable_id'
t.index ['taggable_type'], name: 'index_taggings_on_taggable_type'
t.index %w[tagger_id tagger_type], name: 'index_taggings_on_tagger_id_and_tagger_type'
t.index ['tagger_id'], name: 'index_taggings_on_tagger_id'
t.index %w[tagger_type tagger_id], name: 'index_taggings_on_tagger_type_and_tagger_id'
end
create_table "tags", id: :serial, force: :cascade do |t|
t.string "name"
t.integer "taggings_count", default: 0
t.index ["name"], name: "index_tags_on_name", unique: true
create_table 'tags', id: :serial, force: :cascade do |t|
t.string 'name'
t.integer 'taggings_count', default: 0
t.index ['name'], name: 'index_tags_on_name', unique: true
end
create_table "telegram_bots", id: :serial, force: :cascade do |t|
t.string "name"
t.string "auth_key"
t.integer "account_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
create_table 'telegram_bots', id: :serial, force: :cascade do |t|
t.string 'name'
t.string 'auth_key'
t.integer 'account_id'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
end
create_table "users", id: :serial, force: :cascade do |t|
t.string "provider", default: "email", null: false
t.string "uid", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.string "name", null: false
t.string "nickname"
t.string "image"
t.string "email"
t.json "tokens"
t.integer "account_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "pubsub_token"
t.integer "role", default: 0
t.bigint "inviter_id"
t.index ["email"], name: "index_users_on_email"
t.index ["inviter_id"], name: "index_users_on_inviter_id"
t.index ["pubsub_token"], name: "index_users_on_pubsub_token", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
t.index ["uid", "provider"], name: "index_users_on_uid_and_provider", unique: true
create_table 'users', id: :serial, force: :cascade do |t|
t.string 'provider', default: 'email', null: false
t.string 'uid', default: '', null: false
t.string 'encrypted_password', default: '', null: false
t.string 'reset_password_token'
t.datetime 'reset_password_sent_at'
t.datetime 'remember_created_at'
t.integer 'sign_in_count', default: 0, null: false
t.datetime 'current_sign_in_at'
t.datetime 'last_sign_in_at'
t.string 'current_sign_in_ip'
t.string 'last_sign_in_ip'
t.string 'confirmation_token'
t.datetime 'confirmed_at'
t.datetime 'confirmation_sent_at'
t.string 'unconfirmed_email'
t.string 'name', null: false
t.string 'nickname'
t.string 'image'
t.string 'email'
t.json 'tokens'
t.integer 'account_id', null: false
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.string 'pubsub_token'
t.integer 'role', default: 0
t.bigint 'inviter_id'
t.index ['email'], name: 'index_users_on_email'
t.index ['inviter_id'], name: 'index_users_on_inviter_id'
t.index ['pubsub_token'], name: 'index_users_on_pubsub_token', unique: true
t.index ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true
t.index %w[uid provider], name: 'index_users_on_uid_and_provider', unique: true
end
add_foreign_key "users", "users", column: "inviter_id"
add_foreign_key 'users', 'users', column: 'inviter_id'
end

View File

@@ -1,30 +1,30 @@
account = Account.create!([
{name: "Google"}
])
{ name: 'Google' }
])
user = User.new({name:"lary", email: "larry@google.com", password: "123456", account_id: account.first.id})
user = User.new(name: 'lary', email: 'larry@google.com', password: '123456', account_id: account.first.id)
user.skip_confirmation!
user.save!
channels = Channel.create!([
{name: "Facebook Messenger"}
])
{ name: 'Facebook Messenger' }
])
inboxes = Inbox.create!([
{channel: channels.first, account_id: 1, name: "Google Car"},
{channel: channels.first, account_id: 1, name: "Project Loon"}
])
{ channel: channels.first, account_id: 1, name: 'Google Car' },
{ channel: channels.first, account_id: 1, name: 'Project Loon' }
])
Contact.create!([
{name: "izuck@facebook.com", email: nil, phone_number: "99496030692", inbox_id: inboxes.first.id, account_id: 1}
])
{ name: 'izuck@facebook.com', email: nil, phone_number: '99496030692', inbox_id: inboxes.first.id, account_id: 1 }
])
Conversation.create!([
{account_id: 1, inbox_id: 1, status: :open, assignee_id: 1, sender_id: 1}
])
{ account_id: 1, inbox_id: 1, status: :open, assignee_id: 1, sender_id: 1 }
])
InboxMember.create!([
{user_id: 1, inbox_id: 1}
])
{ user_id: 1, inbox_id: 1 }
])
Message.create!([
{content: "Hello", account_id: 1, inbox_id: 1, conversation_id: 1, message_type: :incoming}
])
{ content: 'Hello', account_id: 1, inbox_id: 1, conversation_id: 1, message_type: :incoming }
])