Skip to content

Commit

Permalink
Add supported Ruby versions - close #39
Browse files Browse the repository at this point in the history
The specs were failing on newer versions of Ruby due to ActiveRecord 6. There was a hardcoded check for version 5, and this was causing a conditional spec to fallback to version 4. The spec has been updated to now test accordingly when the version is either below or above 5 (this is where the actual distinction lies).
  • Loading branch information
davidmyersdev committed Apr 28, 2020
1 parent 90d33b4 commit 4f9ff62
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ script:
rvm:
- 2.3
- 2.4
- 2.5
- 2.6
- 2.7
7 changes: 0 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,3 @@

load File.dirname(__FILE__) + '/schema.rb'
require File.dirname(__FILE__) + '/models.rb'

rails5 = `bundle show activerecord`.strip.split('/').last =~ /activerecord-5\./
exclude_rails = rails5 ? 4 : 5 # don't run tests for the version of rails we are NOT using

RSpec.configure do |config|
config.filter_run_excluding rails: exclude_rails
end
27 changes: 11 additions & 16 deletions spec/sql_footprint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,19 @@
)
end

it 'formats selects', rails: 4 do
it 'formats selects' do
Widget.where(name: SecureRandom.uuid, quantity: 1).last
expect(statements.to_a).to include(
'SELECT "widgets".* FROM "widgets" ' \
'WHERE "widgets"."name" = ? AND ' \
'"widgets"."quantity" = ? ' \
'ORDER BY "widgets"."id" DESC LIMIT 1'
)
end

it 'formats selects', rails: 5 do
Widget.where(name: SecureRandom.uuid, quantity: 1).last
expect(statements.to_a).to include(
'SELECT "widgets".* FROM "widgets" ' \
'WHERE "widgets"."name" = ? AND ' \
'"widgets"."quantity" = ? ' \
'ORDER BY "widgets"."id" DESC LIMIT ?'
)
clean_statements = statements.to_a.map(&:squish)

sql = <<-SQL.squish
SELECT "widgets".* FROM "widgets"
WHERE "widgets"."name" = ? AND
"widgets"."quantity" = ?
ORDER BY "widgets"."id" DESC LIMIT #{ActiveRecord::VERSION::MAJOR < 5 ? '1' : '?'}
SQL

expect(clean_statements).to include(sql)
end

it 'dedupes the same sql' do
Expand Down
2 changes: 1 addition & 1 deletion sql_footprint.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'activerecord', ['>= 3.0']
spec.add_dependency 'activesupport', ['>= 3.0']

spec.add_development_dependency 'bundler', '~> 1.7'
spec.add_development_dependency 'bundler', ['>= 1.7', '< 3.0']
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'pry'
Expand Down

0 comments on commit 4f9ff62

Please sign in to comment.