Add attribute TelegramBot#username
This commit is contained in:
parent
c77bfd9864
commit
655c9fd36f
7 changed files with 41 additions and 1 deletions
|
@ -1,6 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TelegramBot < ApplicationRecord
|
||||
USERNAME_RE = /\A[a-z_][a-z0-9_]*\z/i.freeze
|
||||
|
||||
validates :secret, presence: true
|
||||
validates :api_token, presence: true
|
||||
|
||||
validates :username,
|
||||
allow_nil: true,
|
||||
presence: true,
|
||||
format: USERNAME_RE
|
||||
end
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
<th scope="col">
|
||||
<%= TelegramBot.human_attribute_name :api_token %>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<%= TelegramBot.human_attribute_name :username %>
|
||||
</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -21,6 +24,8 @@
|
|||
<td scope="row"><%= telegram_bot.id %></td>
|
||||
<td><%= telegram_bot.secret %></td>
|
||||
<td><%= telegram_bot.api_token %></td>
|
||||
<td><%= truncate telegram_bot.username, length: 20 %></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
|
|
@ -72,6 +72,7 @@ en:
|
|||
id: ID
|
||||
secret: Secret
|
||||
api_token: API token
|
||||
username: Username
|
||||
user:
|
||||
id: ID
|
||||
confirmation_sent_at: Confirmation sent at
|
||||
|
|
|
@ -72,6 +72,7 @@ ru:
|
|||
id: ID
|
||||
secret: Секрет
|
||||
api_token: Токен API
|
||||
username: Имя пользователя
|
||||
user:
|
||||
id: ID
|
||||
confirmation_sent_at: Дата отправки подтверждения
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddUsernameToTelegramBots < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :telegram_bots, :username, :string, index: 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: 2018_12_06_224446) do
|
||||
ActiveRecord::Schema.define(version: 2018_12_07_002553) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -133,6 +133,7 @@ ActiveRecord::Schema.define(version: 2018_12_06_224446) do
|
|||
t.datetime "updated_at", null: false
|
||||
t.string "secret", null: false
|
||||
t.string "api_token", null: false
|
||||
t.string "username"
|
||||
end
|
||||
|
||||
create_table "user_omniauths", force: :cascade do |t|
|
||||
|
|
|
@ -7,4 +7,22 @@ RSpec.describe TelegramBot do
|
|||
|
||||
it { is_expected.to validate_presence_of :secret }
|
||||
it { is_expected.to validate_presence_of :api_token }
|
||||
|
||||
describe '#username' do
|
||||
def allow_value(*)
|
||||
super.for :username
|
||||
end
|
||||
|
||||
it { is_expected.to allow_value nil }
|
||||
|
||||
it { is_expected.not_to allow_value '' }
|
||||
it { is_expected.not_to allow_value ' ' }
|
||||
it { is_expected.not_to allow_value ' ' * rand(2..10) }
|
||||
|
||||
it { is_expected.to allow_value Faker::Internet.username nil, %w[_] }
|
||||
it { is_expected.to allow_value 'foo123_456_BAR' }
|
||||
|
||||
it { is_expected.not_to allow_value Faker::Internet.email }
|
||||
it { is_expected.not_to allow_value Faker::PhoneNumber.phone_number }
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue