Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Rails, Fixed Tests, Updated Readme #34

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ end
```

#### Outputs
After running your specs you'll find a 'footprint.*.sql' file in your project.
After running your specs you'll find a 'footprint.*.sql' file in your db directory.
Footprints are per-database. For example, if you're using DB1 AND DB2 in your app, you would end up with two footprint files. (footprint.db1.sql, footprint.db2.sql)

If you're using an in-memory database, you'll end up with `footprint.:memory:.sql`.
Expand All @@ -63,12 +63,13 @@ end
Or if you're using FactoryGirl you could do something like this:
```ruby
RSpec.configure do |config|
module FactoryBoy
module FactoryKid
def create(*args)
SqlFootprint.exclude { FactoryGirl.create(*args) }
``` FactoryGirl changed their gem name to FactoryBot ```
SqlFootprint.exclude { FactoryBot.create(*args) }
end
end
config.include FactoryBoy
config.include FactoryKid
end
```

Expand Down
23 changes: 16 additions & 7 deletions spec/sql_footprint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,23 @@
)
end

it 'formats selects' do
it 'appends the statement count by 1' do
expect do
Widget.where(name: SecureRandom.uuid, quantity: 1).last
end.to change { statements.count }.by(+1)
end

it 'appends 1 sql statement' 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'
)

sql_fragments = ['SELECT "widgets".* FROM "widgets"',
'WHERE "widgets"."name" = ?',
'AND',
'widgets"."quantity" = ?',
'ORDER BY "widgets"."id" DESC', 'LIMIT ?']
sql_fragments.all? do |fragment|
expect(statements.to_a.find { |sql| sql.match(fragment) }).to be_truthy
end
end

it 'dedupes the same sql' do
Expand Down
11 changes: 6 additions & 5 deletions sql_footprint.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'activerecord', ['>= 3.0', '< 5.0']
spec.add_dependency 'activesupport', ['>= 3.0', '< 5.0']
# ruby version 2 uses older active record
spec.add_dependency 'activerecord', '~> 4.2.10'
spec.add_dependency 'activesupport', '~> 4.2.10'

spec.add_development_dependency 'bundler', '~> 1.7'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'rspec', '~> 3.5.0'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'sqlite3'
spec.add_development_dependency 'rubocop', '~> 0.37.0'
spec.add_development_dependency 'rubocop-rspec'
spec.add_development_dependency 'rubocop', '~> 0.39.0'
spec.add_development_dependency 'rubocop-rspec', '~> 1.4.1'
end