active_record_simple_execute 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +8 -0
- data/LICENSE +21 -0
- data/README.md +86 -0
- data/Rakefile +21 -0
- data/lib/active_record_simple_execute.rb +34 -0
- data/lib/active_record_simple_execute/version.rb +5 -0
- data/test/dummy_app/Rakefile +7 -0
- data/test/dummy_app/app/assets/config/manifest.js +3 -0
- data/test/dummy_app/app/assets/javascripts/application.js +0 -0
- data/test/dummy_app/app/assets/stylesheets/application.css +3 -0
- data/test/dummy_app/app/controllers/application_controller.rb +3 -0
- data/test/dummy_app/app/models/application_record.rb +3 -0
- data/test/dummy_app/app/models/post.rb +3 -0
- data/test/dummy_app/app/views/layouts/application.html.erb +14 -0
- data/test/dummy_app/config.ru +4 -0
- data/test/dummy_app/config/application.rb +70 -0
- data/test/dummy_app/config/boot.rb +10 -0
- data/test/dummy_app/config/database.yml +20 -0
- data/test/dummy_app/config/environment.rb +5 -0
- data/test/dummy_app/config/environments/development.rb +30 -0
- data/test/dummy_app/config/environments/production.rb +60 -0
- data/test/dummy_app/config/environments/test.rb +41 -0
- data/test/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy_app/config/initializers/inflections.rb +10 -0
- data/test/dummy_app/config/initializers/mime_types.rb +5 -0
- data/test/dummy_app/config/initializers/secret_token.rb +11 -0
- data/test/dummy_app/config/initializers/session_store.rb +8 -0
- data/test/dummy_app/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy_app/config/locales/en.yml +5 -0
- data/test/dummy_app/config/routes.rb +6 -0
- data/test/dummy_app/config/secrets.yml +22 -0
- data/test/dummy_app/db/migrate/20210128155312_set_up_test_tables.rb +28 -0
- data/test/dummy_app/db/test +0 -0
- data/test/dummy_app/db/test.sqlite3 +0 -0
- data/test/dummy_app/log/test.log +612 -0
- data/test/test_helper.rb +43 -0
- data/test/unit/active_record_simple_execute_test.rb +63 -0
- metadata +227 -0
data/test/test_helper.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require "active_record_simple_execute"
|
5
|
+
|
6
|
+
### Instantiates Rails
|
7
|
+
require File.expand_path("../dummy_app/config/environment.rb", __FILE__)
|
8
|
+
|
9
|
+
require "rails/test_help"
|
10
|
+
|
11
|
+
class ActiveSupport::TestCase
|
12
|
+
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
13
|
+
fixtures :all
|
14
|
+
end
|
15
|
+
|
16
|
+
Rails.backtrace_cleaner.remove_silencers!
|
17
|
+
|
18
|
+
require 'minitest/reporters'
|
19
|
+
Minitest::Reporters.use!(
|
20
|
+
Minitest::Reporters::DefaultReporter.new,
|
21
|
+
ENV,
|
22
|
+
Minitest.backtrace_filter
|
23
|
+
)
|
24
|
+
|
25
|
+
require "minitest/autorun"
|
26
|
+
|
27
|
+
############################################################### MIGRATIONS AND DATA
|
28
|
+
if ActiveRecord.gem_version >= Gem::Version.new("6.0")
|
29
|
+
ActiveRecord::MigrationContext.new(File.expand_path("dummy_app/db/migrate/", __dir__), ActiveRecord::SchemaMigration).migrate
|
30
|
+
elsif ActiveRecord.gem_version >= Gem::Version.new("5.2")
|
31
|
+
ActiveRecord::MigrationContext.new(File.expand_path("dummy_app/db/migrate/", __dir__)).migrate
|
32
|
+
else
|
33
|
+
ActiveRecord::Migrator.migrate File.expand_path("dummy_app/db/migrate/", __dir__)
|
34
|
+
end
|
35
|
+
|
36
|
+
[Post].each do |klass|
|
37
|
+
if defined?(SQLite3)
|
38
|
+
ActiveRecord::Base.connection.execute("DELETE FROM #{klass.table_name};")
|
39
|
+
ActiveRecord::Base.connection.execute("UPDATE `sqlite_sequence` SET `seq` = 0 WHERE `name` = '#{klass.table_name}';")
|
40
|
+
else
|
41
|
+
ActiveRecord::Base.connection.execute("TRUNCATE TABLE #{klass.table_name}")
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ActiveRecordSimpleExecuteTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
end
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_exposes_version
|
12
|
+
assert ActiveRecordSimpleExecute::VERSION.is_a?(String)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_no_results
|
16
|
+
sql = <<~SQL.squish
|
17
|
+
SELECT * FROM posts WHERE posts.title = 'bar'
|
18
|
+
SQL
|
19
|
+
|
20
|
+
results = ActiveRecord::Base.simple_execute(sql)
|
21
|
+
|
22
|
+
assert_kind_of Array, results
|
23
|
+
|
24
|
+
assert_empty results
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_has_results
|
28
|
+
Post.create!(title: "bar")
|
29
|
+
|
30
|
+
sql = <<~SQL.squish
|
31
|
+
SELECT * FROM posts WHERE posts.title = 'bar'
|
32
|
+
SQL
|
33
|
+
|
34
|
+
results = ActiveRecord::Base.simple_execute(sql)
|
35
|
+
|
36
|
+
assert_kind_of Array, results
|
37
|
+
|
38
|
+
assert_equal 1, results.size
|
39
|
+
|
40
|
+
assert_kind_of Hash, results.first
|
41
|
+
|
42
|
+
assert_equal "bar", results.first["title"]
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_with_sql_vars
|
46
|
+
Post.create!(title: "bar")
|
47
|
+
|
48
|
+
sql = <<~SQL.squish
|
49
|
+
SELECT * FROM posts WHERE posts.title = :title
|
50
|
+
SQL
|
51
|
+
|
52
|
+
results = ActiveRecord::Base.simple_execute(sql, title: "bar")
|
53
|
+
|
54
|
+
assert_kind_of Array, results
|
55
|
+
|
56
|
+
assert_equal 1, results.size
|
57
|
+
|
58
|
+
assert_kind_of Hash, results.first
|
59
|
+
|
60
|
+
assert_equal "bar", results.first["title"]
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_record_simple_execute
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Weston Ganger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-05-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-reporters
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: appraisal
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: warning
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Sanitize and Execute your raw SQL queries in ActiveRecord and Rails with
|
126
|
+
a much more intuitive and shortened syntax.
|
127
|
+
email:
|
128
|
+
- weston@westonganger.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- CHANGELOG.md
|
134
|
+
- LICENSE
|
135
|
+
- README.md
|
136
|
+
- Rakefile
|
137
|
+
- lib/active_record_simple_execute.rb
|
138
|
+
- lib/active_record_simple_execute/version.rb
|
139
|
+
- test/dummy_app/Rakefile
|
140
|
+
- test/dummy_app/app/assets/config/manifest.js
|
141
|
+
- test/dummy_app/app/assets/javascripts/application.js
|
142
|
+
- test/dummy_app/app/assets/stylesheets/application.css
|
143
|
+
- test/dummy_app/app/controllers/application_controller.rb
|
144
|
+
- test/dummy_app/app/models/application_record.rb
|
145
|
+
- test/dummy_app/app/models/post.rb
|
146
|
+
- test/dummy_app/app/views/layouts/application.html.erb
|
147
|
+
- test/dummy_app/config.ru
|
148
|
+
- test/dummy_app/config/application.rb
|
149
|
+
- test/dummy_app/config/boot.rb
|
150
|
+
- test/dummy_app/config/database.yml
|
151
|
+
- test/dummy_app/config/environment.rb
|
152
|
+
- test/dummy_app/config/environments/development.rb
|
153
|
+
- test/dummy_app/config/environments/production.rb
|
154
|
+
- test/dummy_app/config/environments/test.rb
|
155
|
+
- test/dummy_app/config/initializers/backtrace_silencers.rb
|
156
|
+
- test/dummy_app/config/initializers/inflections.rb
|
157
|
+
- test/dummy_app/config/initializers/mime_types.rb
|
158
|
+
- test/dummy_app/config/initializers/secret_token.rb
|
159
|
+
- test/dummy_app/config/initializers/session_store.rb
|
160
|
+
- test/dummy_app/config/initializers/wrap_parameters.rb
|
161
|
+
- test/dummy_app/config/locales/en.yml
|
162
|
+
- test/dummy_app/config/routes.rb
|
163
|
+
- test/dummy_app/config/secrets.yml
|
164
|
+
- test/dummy_app/db/migrate/20210128155312_set_up_test_tables.rb
|
165
|
+
- test/dummy_app/db/test
|
166
|
+
- test/dummy_app/db/test.sqlite3
|
167
|
+
- test/dummy_app/log/test.log
|
168
|
+
- test/test_helper.rb
|
169
|
+
- test/unit/active_record_simple_execute_test.rb
|
170
|
+
homepage: https://github.com/westonganger/active_record_simple_execute
|
171
|
+
licenses:
|
172
|
+
- MIT
|
173
|
+
metadata:
|
174
|
+
source_code_uri: https://github.com/westonganger/active_record_simple_execute
|
175
|
+
changelog_uri: https://github.com/westonganger/active_record_simple_execute/blob/master/CHANGELOG.md
|
176
|
+
post_install_message:
|
177
|
+
rdoc_options: []
|
178
|
+
require_paths:
|
179
|
+
- lib
|
180
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: 1.9.3
|
185
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - ">="
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
requirements: []
|
191
|
+
rubygems_version: 3.1.4
|
192
|
+
signing_key:
|
193
|
+
specification_version: 4
|
194
|
+
summary: Sanitize and Execute your raw SQL queries in ActiveRecord and Rails with
|
195
|
+
a much more intuitive and shortened syntax.
|
196
|
+
test_files:
|
197
|
+
- test/unit/active_record_simple_execute_test.rb
|
198
|
+
- test/test_helper.rb
|
199
|
+
- test/dummy_app/app/models/application_record.rb
|
200
|
+
- test/dummy_app/app/models/post.rb
|
201
|
+
- test/dummy_app/app/controllers/application_controller.rb
|
202
|
+
- test/dummy_app/app/views/layouts/application.html.erb
|
203
|
+
- test/dummy_app/app/assets/config/manifest.js
|
204
|
+
- test/dummy_app/app/assets/javascripts/application.js
|
205
|
+
- test/dummy_app/app/assets/stylesheets/application.css
|
206
|
+
- test/dummy_app/config/secrets.yml
|
207
|
+
- test/dummy_app/config/routes.rb
|
208
|
+
- test/dummy_app/config/locales/en.yml
|
209
|
+
- test/dummy_app/config/environments/production.rb
|
210
|
+
- test/dummy_app/config/environments/development.rb
|
211
|
+
- test/dummy_app/config/environments/test.rb
|
212
|
+
- test/dummy_app/config/environment.rb
|
213
|
+
- test/dummy_app/config/application.rb
|
214
|
+
- test/dummy_app/config/database.yml
|
215
|
+
- test/dummy_app/config/boot.rb
|
216
|
+
- test/dummy_app/config/initializers/backtrace_silencers.rb
|
217
|
+
- test/dummy_app/config/initializers/mime_types.rb
|
218
|
+
- test/dummy_app/config/initializers/session_store.rb
|
219
|
+
- test/dummy_app/config/initializers/wrap_parameters.rb
|
220
|
+
- test/dummy_app/config/initializers/secret_token.rb
|
221
|
+
- test/dummy_app/config/initializers/inflections.rb
|
222
|
+
- test/dummy_app/config.ru
|
223
|
+
- test/dummy_app/Rakefile
|
224
|
+
- test/dummy_app/db/test
|
225
|
+
- test/dummy_app/db/test.sqlite3
|
226
|
+
- test/dummy_app/db/migrate/20210128155312_set_up_test_tables.rb
|
227
|
+
- test/dummy_app/log/test.log
|