-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add rubocop and apply code style changes
- Loading branch information
Showing
9 changed files
with
84 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ gemfile: | |
- gemfiles/5.0.gemfile | ||
|
||
rvm: | ||
- '2.3.1' | ||
- '2.3.3' | ||
|
||
addons: | ||
postgresql: '9.4' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
appraise "3.2" do | ||
gem "activerecord", "~> 3.2.21" | ||
# frozen_string_literal: true | ||
|
||
appraise '3.2' do | ||
gem 'activerecord', '~> 3.2.21' | ||
end | ||
|
||
appraise "4.0" do | ||
gem "activerecord", "~> 4.0.0" | ||
appraise '4.0' do | ||
gem 'activerecord', '~> 4.0.0' | ||
end | ||
|
||
appraise "4.1" do | ||
gem "activerecord", "~> 4.1.0" | ||
appraise '4.1' do | ||
gem 'activerecord', '~> 4.1.0' | ||
end | ||
|
||
appraise "4.2" do | ||
gem "activerecord", "~> 4.2.0" | ||
appraise '4.2' do | ||
gem 'activerecord', '~> 4.2.0' | ||
end | ||
|
||
appraise "5.0" do | ||
gem "activerecord", "~> 5.0.0" | ||
appraise '5.0' do | ||
gem 'activerecord', '~> 5.0.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
require "bundler/gem_tasks" | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
|
||
task :default => :spec | ||
task default: :spec | ||
|
||
RSpec::Core::RakeTask.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe SqlQuery::Config do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe SqlQuery do | ||
|
||
let(:options) { { email: '[email protected]' } } | ||
let(:file_name) { :get_player_by_email } | ||
let(:query) { described_class.new(file_name, options) } | ||
|
@@ -11,7 +12,6 @@ class Model < ActiveRecord::Base | |
end | ||
|
||
describe '#initialize' do | ||
|
||
it 'sets instance variables for all options' do | ||
expect(query.instance_variable_get(:@email)).to eq '[email protected]' | ||
end | ||
|
@@ -28,7 +28,9 @@ class Model < ActiveRecord::Base | |
let(:file_name) { { do: 'something' } } | ||
|
||
it 'raises ArgumentError' do | ||
expect{ query }.to raise_error(ArgumentError, 'SQL file name should be String or Symbol') | ||
expect { query } | ||
.to raise_error(ArgumentError, | ||
'SQL file name should be String or Symbol') | ||
end | ||
end | ||
|
||
|
@@ -51,15 +53,17 @@ class Model < ActiveRecord::Base | |
let(:file_name) { :not_exists } | ||
|
||
it 'raises error' do | ||
expect { query.send(:file_path) }.to raise_error('File not found: not_exists') | ||
expect { query.send(:file_path) } | ||
.to raise_error('File not found: not_exists') | ||
end | ||
end | ||
|
||
context 'when there are more than one matching files' do | ||
let(:file_name) { :duplicated } | ||
|
||
it 'raises error' do | ||
expect{ query.send(:file_path) }.to raise_error.with_message(/More than one file found:/) | ||
expect { query.send(:file_path) } | ||
.to raise_error.with_message(/More than one file found:/) | ||
end | ||
end | ||
end | ||
|
@@ -70,14 +74,15 @@ class Model < ActiveRecord::Base | |
let(:file_name) { 'fname' } | ||
|
||
it 'sets it as dir for file' do | ||
expect(query.send(:path)).to eq("/path_to_file/fname.{sql.erb,erb.sql}") | ||
expect(query.send(:path)).to eq('/path_to_file/fname.{sql.erb,erb.sql}') | ||
end | ||
end | ||
end | ||
|
||
describe '#sql' do | ||
it 'returns query string' do | ||
expect(query.sql).to eq "SELECT *\nFROM players\nWHERE email = '[email protected]'\n" | ||
expect(query.sql) | ||
.to eq("SELECT *\nFROM players\nWHERE email = '[email protected]'\n") | ||
end | ||
|
||
context 'when file is .erb.sql' do | ||
|
@@ -92,15 +97,16 @@ class Model < ActiveRecord::Base | |
|
||
describe '#pretty_sql' do | ||
it 'returns query string' do | ||
expect(query.pretty_sql).to eq "SELECT *\nFROM players\nWHERE email = '[email protected]'\n" | ||
expect(query.pretty_sql) | ||
.to eq("SELECT *\nFROM players\nWHERE email = '[email protected]'\n") | ||
end | ||
end | ||
|
||
describe '#explain' do | ||
let(:explain) { query.explain } | ||
it 'returns explain string' do | ||
expect(explain).to include 'EXPLAIN for:' | ||
expect(explain).to include "FROM players" | ||
expect(explain).to include 'FROM players' | ||
expect(explain).to include "WHERE email = '[email protected]'" | ||
expect(explain).to include 'QUERY PLAN' | ||
expect(explain).to include 'Seq Scan on players' | ||
|
@@ -116,12 +122,12 @@ class Model < ActiveRecord::Base | |
|
||
after do | ||
ActiveRecord::Base.connection.execute( | ||
"DELETE FROM players" | ||
'DELETE FROM players' | ||
) | ||
end | ||
|
||
it 'returns data from database' do | ||
expect(query.execute).to eq [{ 'email' => '[email protected]'}] | ||
expect(query.execute).to eq [{ 'email' => '[email protected]' }] | ||
end | ||
|
||
context 'when prepare argument is true' do | ||
|
@@ -142,7 +148,8 @@ class Model < ActiveRecord::Base | |
describe '#partial' do | ||
let(:file_name) { :get_player_by_email_with_template } | ||
it 'resolves partials as parts of sql queries' do | ||
expect(query.sql).to eq("SELECT *\nFROM players\nWHERE players.email = '[email protected]'\n\n") | ||
expect(query.sql) | ||
.to eq("SELECT *\nFROM players\nWHERE players.email = '[email protected]'\n\n") | ||
end | ||
|
||
context 'when partial name is string with file path' do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,37 @@ | ||
# coding: utf-8 | ||
# frozen_string_literal: true | ||
|
||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "sql_query" | ||
spec.version = "0.6.0" | ||
spec.authors = ["sufleR"] | ||
spec.email = ["[email protected]"] | ||
spec.summary = %q{Ruby gem to load and execute SQL queries from `.sql.erb` templates} | ||
spec.description = %q{ | ||
spec.name = 'sql_query' | ||
spec.version = '0.6.0' | ||
spec.authors = ['sufleR'] | ||
spec.email = ['[email protected]'] | ||
spec.summary = 'Ruby gem to load and execute SQL queries from `.sql.erb` templates' | ||
spec.description = " | ||
It makes working with pure SQL easier with syntax highlighting. | ||
Let's you clean your Ruby code from SQL strings. | ||
} | ||
spec.homepage = "https://github.com/sufleR/sql_query" | ||
spec.license = "MIT" | ||
" | ||
spec.homepage = 'https://github.com/sufleR/sql_query' | ||
spec.license = 'MIT' | ||
|
||
spec.files = `git ls-files -z`.split("\x0") | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
spec.require_paths = ["lib"] | ||
spec.require_paths = ['lib'] | ||
|
||
spec.required_ruby_version = ">= 1.9.3" | ||
spec.required_ruby_version = '>= 1.9.3' | ||
|
||
spec.add_dependency "activerecord", ">= 3.2" | ||
spec.add_development_dependency "bundler", "~> 1.13" | ||
spec.add_development_dependency "rake", "~> 11.3" | ||
spec.add_development_dependency "rspec", "~> 3.4" | ||
spec.add_development_dependency "pg", "~> 0.18" | ||
spec.add_development_dependency "pry", "~> 0.10" | ||
spec.add_development_dependency "with_model", "~> 1.2" | ||
spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4" | ||
spec.add_development_dependency "appraisal" | ||
spec.add_dependency 'activerecord', '>= 3.2' | ||
spec.add_development_dependency 'bundler', '~> 1.13' | ||
spec.add_development_dependency 'rake', '~> 11.3' | ||
spec.add_development_dependency 'rspec', '~> 3.4' | ||
spec.add_development_dependency 'pg', '~> 0.18' | ||
spec.add_development_dependency 'pry', '~> 0.10' | ||
spec.add_development_dependency 'with_model', '~> 1.2' | ||
spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4' | ||
spec.add_development_dependency 'appraisal' | ||
spec.add_development_dependency 'rubocop' | ||
end |