Skip to content

Commit

Permalink
Merge pull request zdennis#760 from desheikh/enable-frozen-string-lit…
Browse files Browse the repository at this point in the history
…erals

Enable frozen string literals
  • Loading branch information
jkowens authored Jan 4, 2022
2 parents 82ac0c4 + 35751ed commit 85d697d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ jobs:
- 2.7
env:
- AR_VERSION: 7.0
RUBYOPT: --enable-frozen-string-literal
- AR_VERSION: 6.1
RUBYOPT: --enable-frozen-string-literal
- AR_VERSION: 6.0
RUBYOPT: --enable-frozen-string-literal
include:
- ruby: 2.6
env:
Expand Down
2 changes: 1 addition & 1 deletion lib/activerecord-import/adapters/mysql_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def add_column_for_on_duplicate_key_update( column, options = {} ) # :nodoc:
# Returns a generated ON DUPLICATE KEY UPDATE statement given the passed
# in +args+.
def sql_for_on_duplicate_key_update( table_name, *args ) # :nodoc:
sql = ' ON DUPLICATE KEY UPDATE '
sql = ' ON DUPLICATE KEY UPDATE '.dup
arg = args.first
locking_column = args.last
if arg.is_a?( Array )
Expand Down
8 changes: 4 additions & 4 deletions lib/activerecord-import/adapters/postgresql_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def sql_for_on_duplicate_key_update( table_name, *args ) # :nodoc:
arg = { columns: arg } if arg.is_a?( Array ) || arg.is_a?( String )
return unless arg.is_a?( Hash )

sql = ' ON CONFLICT '
sql = ' ON CONFLICT '.dup
conflict_target = sql_for_conflict_target( arg )

columns = arg.fetch( :columns, [] )
Expand Down Expand Up @@ -179,9 +179,9 @@ def sql_for_conflict_target( args = {} )
if constraint_name.present?
"ON CONSTRAINT #{constraint_name} "
elsif conflict_target.present?
'(' << Array( conflict_target ).reject( &:blank? ).join( ', ' ) << ') '.tap do |sql|
sql << "WHERE #{index_predicate} " if index_predicate
end
sql = '(' + Array( conflict_target ).reject( &:blank? ).join( ', ' ) + ') '
sql += "WHERE #{index_predicate} " if index_predicate
sql
end
end

Expand Down
8 changes: 4 additions & 4 deletions lib/activerecord-import/adapters/sqlite3_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def sql_for_on_duplicate_key_update( table_name, *args ) # :nodoc:
arg = { columns: arg } if arg.is_a?( Array ) || arg.is_a?( String )
return unless arg.is_a?( Hash )

sql = ' ON CONFLICT '
sql = ' ON CONFLICT '.dup
conflict_target = sql_for_conflict_target( arg )

columns = arg.fetch( :columns, [] )
Expand Down Expand Up @@ -150,9 +150,9 @@ def sql_for_conflict_target( args = {} )
conflict_target = args[:conflict_target]
index_predicate = args[:index_predicate]
if conflict_target.present?
'(' << Array( conflict_target ).reject( &:blank? ).join( ', ' ) << ') '.tap do |sql|
sql << "WHERE #{index_predicate} " if index_predicate
end
sql = '(' + Array( conflict_target ).reject( &:blank? ).join( ', ' ) + ') '
sql += "WHERE #{index_predicate} " if index_predicate
sql
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/support/postgresql/import_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def should_support_postgresql_import_functionality
end

describe "with binary field" do
let(:binary_value) { "\xE0'c\xB2\xB0\xB3Bh\\\xC2M\xB1m\\I\xC4r".force_encoding('ASCII-8BIT') }
let(:binary_value) { "\xE0'c\xB2\xB0\xB3Bh\\\xC2M\xB1m\\I\xC4r".dup.force_encoding('ASCII-8BIT') }
it "imports the correct values for binary fields" do
alarms = [Alarm.new(device_id: 1, alarm_type: 1, status: 1, secret_key: binary_value)]
assert_difference "Alarm.count", +1 do
Expand Down

0 comments on commit 85d697d

Please sign in to comment.