Skip to content

Commit

Permalink
rubocop fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jderecho committed Jun 24, 2024
1 parent b9874c8 commit a370bf9
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def create
end

def event_data
# todo move to service action
# TODO: move to service action
case params[:event]
when 'ask_copilot'
event = @conversation.smart_actions.ask_copilot.last
render json: event.present? ? event.event_data : {}
else
render json: {success: false}
render json: { success: false }
end
end
end
5 changes: 2 additions & 3 deletions app/controllers/api/v1/accounts/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ class Api::V1::Accounts::MessagesController < Api::V1::Accounts::BaseController
before_action :set_messages, only: [:index]
before_action :set_current_page, only: [:index]

def index
end
def index; end

private

Expand All @@ -26,4 +25,4 @@ def current_page_messages
def set_current_page
@current_page = params[:page] || 1
end
end
end
10 changes: 4 additions & 6 deletions app/jobs/conversations/activity_message_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ class Conversations::ActivityMessageJob < ApplicationJob
queue_as :high

def perform(conversation, message_params)
begin
conversation.messages.create!(message_params)
rescue StandardError => e
Rails.logger.error e.message
Rails.logger.error e.backtrace.first
end
conversation.messages.create!(message_params)
rescue StandardError => e
Rails.logger.error e.message
Rails.logger.error e.backtrace.first
end
end
2 changes: 1 addition & 1 deletion app/models/concerns/activity_message_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def generate_assignee_change_activity_content(user_name)

def create_assignee_change_activity(user_name)
user_name = activity_message_owner(user_name)

# auto assigned if user_name is nil
# return unless user_name

Expand Down
2 changes: 1 addition & 1 deletion app/models/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class Message < ApplicationRecord
}

scope :filter_by_created_at, ->(range) { where(created_at: range) if range.present? }

scope :filter_by_label, lambda { |selected_label|
joins(:conversation).where(conversations: { cached_label_list: selected_label }) if selected_label.present?
}
Expand Down
2 changes: 1 addition & 1 deletion app/models/smart_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SmartAction < ApplicationRecord
validates :conversation_id, presence: true

scope :ask_copilot, -> { where(event: 'ask_copilot') }

delegate :account, to: :conversation

after_create_commit :execute_after_create_commit_callbacks
Expand Down
14 changes: 7 additions & 7 deletions db/migrate/20240517140740_log_conversation.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
class LogConversation < ActiveRecord::Migration[7.0]
def change
conversation = Conversation.find_by(display_id: 33053)
conversation = Conversation.find_by(display_id: 33_053)

if conversation.present?
puts 'logging conversation'
puts conversation.attributes
conversation.messages.each do |msg|
puts msg.attributes
end
return unless conversation.present?

puts 'logging conversation'
puts conversation.attributes
conversation.messages.each do |msg|
puts msg.attributes
end
end
end
14 changes: 7 additions & 7 deletions db/migrate/20240614160733_add_labels_to_digital_tolk.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
class AddLabelsToDigitalTolk < ActiveRecord::Migration[7.0]
def change
account = Account.find(1)
Digitaltolk::ChangeContactKindService::KIND_LABELS.each do |key, value|
label = account.labels.find_or_create_by({title: value})
Digitaltolk::ChangeContactKindService::KIND_LABELS.each do |_key, value|
label = account.labels.find_or_create_by({ title: value })

label.update({
description: value,
color: Faker::Color.hex_color,
show_on_sidebar: true
})
description: value,
color: Faker::Color.hex_color,
show_on_sidebar: true
})
end
end
end
5 changes: 2 additions & 3 deletions lib/digitaltolk/change_contact_kind_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class ChangeContactKindService
4 => 'anställd_contact'
}


def initialize(account, conversation, contact_kind)
@account = account
@conversation = conversation
Expand All @@ -24,7 +23,7 @@ def perform
private

def toggle_contact_kind_labels
return unless @account.feature_enabled?("required_contact_type")
return unless @account.feature_enabled?('required_contact_type')

updated_labels = (@conversation.cached_label_list_array - KIND_LABELS.values + [KIND_LABELS[@contact_kind]]).uniq
@conversation.update_labels(updated_labels)
Expand All @@ -34,4 +33,4 @@ def toggle_contact_kind
@conversation.update!(contact_kind: @contact_kind)
end
end
end
end
20 changes: 10 additions & 10 deletions spec/controllers/api/v1/accounts/messages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

context 'when authenticated' do
it 'returns messages' do
get api_v1_account_messages_path(account_id: account.id),
get api_v1_account_messages_path(account_id: account.id),
headers: agent.create_new_auth_token

expect(response).to have_http_status(:success)
Expand All @@ -35,8 +35,8 @@
end

it 'returns correct messages count' do
get api_v1_account_messages_path(account_id: account.id, inbox_id: @other_inbox.id),
headers: agent.create_new_auth_token
get api_v1_account_messages_path(account_id: account.id, inbox_id: @other_inbox.id),
headers: agent.create_new_auth_token

expect(response.parsed_body['payload'].size).to eq(7)
end
Expand All @@ -50,8 +50,8 @@
end

it 'returns correct messages count' do
get api_v1_account_messages_path(account_id: account.id, since: 4.days.ago.to_i, until: 2.days.ago.to_i),
headers: agent.create_new_auth_token
get api_v1_account_messages_path(account_id: account.id, since: 4.days.ago.to_i, until: 2.days.ago.to_i),
headers: agent.create_new_auth_token

expect(response.parsed_body['payload'].size).to eq(2)
end
Expand All @@ -66,8 +66,8 @@
end

it 'returns correct messages count' do
get api_v1_account_messages_path(account_id: account.id, team_id: @team.id),
headers: agent.create_new_auth_token
get api_v1_account_messages_path(account_id: account.id, team_id: @team.id),
headers: agent.create_new_auth_token

expect(response.parsed_body['payload'].size).to eq(4)
end
Expand All @@ -80,12 +80,12 @@
end

it 'returns correct messages count' do
get api_v1_account_messages_path(account_id: account.id, label: @label.title),
headers: agent.create_new_auth_token
get api_v1_account_messages_path(account_id: account.id, label: @label.title),
headers: agent.create_new_auth_token

expect(response.parsed_body['payload'].size).to eq(12)
end
end
end
end
end
end

0 comments on commit a370bf9

Please sign in to comment.