obvious_data 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +116 -0
  4. data/Rakefile +16 -0
  5. data/lib/generators/obvious_data_directories_generator.rb +7 -0
  6. data/lib/obvious_data.rb +7 -0
  7. data/lib/obvious_data/command_recorder_methods.rb +28 -0
  8. data/lib/obvious_data/railtie.rb +17 -0
  9. data/lib/obvious_data/schema_methods.rb +28 -0
  10. data/lib/obvious_data/version.rb +3 -0
  11. data/lib/tasks/obvious_data_tasks.rake +4 -0
  12. data/spec/dummy/README.rdoc +261 -0
  13. data/spec/dummy/Rakefile +7 -0
  14. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  15. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  16. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  17. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  18. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  19. data/spec/dummy/config.ru +4 -0
  20. data/spec/dummy/config/application.rb +59 -0
  21. data/spec/dummy/config/boot.rb +10 -0
  22. data/spec/dummy/config/database.yml +19 -0
  23. data/spec/dummy/config/environment.rb +5 -0
  24. data/spec/dummy/config/environments/development.rb +37 -0
  25. data/spec/dummy/config/environments/production.rb +67 -0
  26. data/spec/dummy/config/environments/test.rb +37 -0
  27. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  28. data/spec/dummy/config/initializers/inflections.rb +15 -0
  29. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  30. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  31. data/spec/dummy/config/initializers/session_store.rb +8 -0
  32. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  33. data/spec/dummy/config/locales/en.yml +5 -0
  34. data/spec/dummy/config/routes.rb +58 -0
  35. data/spec/dummy/db/migrate/20140724185749_create_dummy_table.rb +8 -0
  36. data/spec/dummy/db/migrate/20140724192457_create_dummy_trigger_func.rb +12 -0
  37. data/spec/dummy/db/structure.sql +112 -0
  38. data/spec/dummy/db/test.sqlite3 +0 -0
  39. data/spec/dummy/log/development.log +252 -0
  40. data/spec/dummy/log/test.log +8287 -0
  41. data/spec/dummy/public/404.html +26 -0
  42. data/spec/dummy/public/422.html +26 -0
  43. data/spec/dummy/public/500.html +25 -0
  44. data/spec/dummy/public/favicon.ico +0 -0
  45. data/spec/dummy/script/rails +6 -0
  46. data/spec/migrations_spec.rb +105 -0
  47. data/spec/sanity_spec.rb +7 -0
  48. data/spec/spec_helper.rb +28 -0
  49. data/spec/support/db/functions/one.sql +3 -0
  50. data/spec/support/db/triggers/one_t.sql +3 -0
  51. data/spec/support/db/views/one_v.sql +2 -0
  52. metadata +203 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+ require 'rake'
3
+
4
+ describe ObviousData::SchemaMethods do
5
+ after{ reset_db! }
6
+ before(:context){ add_sql_sources }
7
+ after(:context){ remove_sql_sources }
8
+
9
+ let(:migration){ ActiveRecord::Migration.new }
10
+
11
+ describe '#execute_function_file' do
12
+ it 'executes specified function from the db/functions/ dir' do
13
+ expect{ select_function(:one) }.to raise_error
14
+
15
+ migration.execute_function_file('one')
16
+ expect( select_function(:one) ).to eq( {'one' => '1'} )
17
+ end
18
+ end
19
+
20
+ describe '#drop_function' do
21
+ it 'drops the specified function' do
22
+ migration.execute_function_file('one')
23
+ expect( select_function(:one) ).to eq( {'one' => '1'} )
24
+
25
+ migration.drop_function('one()')
26
+ expect{ select_function(:one) }.to raise_error
27
+ end
28
+ end
29
+
30
+ describe '#execute_view_file' do
31
+ it 'executes specified view from the db/views/ dir' do
32
+ expect{ select_view(:one_v) }.to raise_error
33
+
34
+ migration.execute_view_file('one_v')
35
+ expect( select_view(:one_v) ).to eq( '1' )
36
+ end
37
+ end
38
+
39
+ describe '#drop_view' do
40
+ it 'drops the specified view' do
41
+ migration.execute_view_file('one_v')
42
+ expect( select_view(:one_v) ).to eq( '1' )
43
+
44
+ migration.drop_view('one_v')
45
+ expect{ select_view(:one_v) }.to raise_error
46
+ end
47
+ end
48
+
49
+ describe '#execute_trigger_file' do
50
+ it 'executes specified trigger from the db/triggers/ dir' do
51
+ expect(trigger_exists?(:one_t)).to be_falsey
52
+
53
+ migration.execute_trigger_file('one_t')
54
+ expect(trigger_exists?(:one_t)).to be_truthy
55
+ end
56
+ end
57
+
58
+ describe '#drop_trigger' do
59
+ it 'drops the specified trigger on the specified table' do
60
+ migration.execute_trigger_file('one_t')
61
+ expect(trigger_exists?(:one_t)).to be_truthy
62
+
63
+ migration.drop_trigger('one_t', 'dummy')
64
+ expect(trigger_exists?(:one_t)).to be_falsey
65
+ end
66
+ end
67
+
68
+ def select_function(function)
69
+ ActiveRecord::Base.connection.execute("select * from #{function}()").first
70
+ end
71
+
72
+ def select_view(view)
73
+ ActiveRecord::Base.connection.execute("select * from #{view}").first.values.first
74
+ end
75
+
76
+ def trigger_exists?(trigger)
77
+ ActiveRecord::Base.connection.execute("select true from pg_trigger where tgname = '#{trigger}'").first
78
+ end
79
+
80
+ def reset_db!
81
+ ActiveRecord::Base.connection.execute "drop function if exists one()"
82
+ ActiveRecord::Base.connection.execute "drop view if exists one_v"
83
+ ActiveRecord::Base.connection.execute "drop trigger if exists one_t on dummy"
84
+ end
85
+
86
+ def add_sql_sources
87
+ %w[functions triggers views].each do |dir|
88
+ FileUtils.copy_entry(File.join(sql_sources_root, dir), File.join(sql_sources_target, dir))
89
+ end
90
+ end
91
+
92
+ def remove_sql_sources
93
+ %w[functions triggers views].each do |dir|
94
+ FileUtils.rm_rf(File.join(sql_sources_target, dir))
95
+ end
96
+ end
97
+
98
+ def sql_sources_root
99
+ "#{File.dirname(__FILE__)}/support/db/"
100
+ end
101
+
102
+ def sql_sources_target
103
+ "#{File.dirname(__FILE__)}/dummy/db/"
104
+ end
105
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'sanity' do
4
+ it 'checks sanity' do
5
+ expect(ObviousData).to be_kind_of(Module)
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ # Configure Rails Environment
9
+ ENV["RAILS_ENV"] = "test"
10
+ require 'pry'
11
+
12
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
13
+
14
+ Rails.backtrace_cleaner.remove_silencers!
15
+
16
+ # Load support files
17
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
18
+
19
+ RSpec.configure do |config|
20
+ config.run_all_when_everything_filtered = true
21
+ config.filter_run :focus
22
+
23
+ # Run specs in random order to surface order dependencies. If you find an
24
+ # order dependency and want to debug it, you can fix the order by providing
25
+ # the seed, which is printed after each run.
26
+ # --seed 1234
27
+ config.order = 'random'
28
+ end
@@ -0,0 +1,3 @@
1
+ CREATE FUNCTION one() RETURNS integer AS $$
2
+ SELECT 1 AS result;
3
+ $$ LANGUAGE SQL;
@@ -0,0 +1,3 @@
1
+ create trigger one_t
2
+ after update on dummy
3
+ for each row execute procedure do_dummy();
@@ -0,0 +1,2 @@
1
+ create or replace view one_v as
2
+ select 1;
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: obvious_data
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Suan-Aik Yeo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 5.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 5.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: pg
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 3.0.0
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: 4.0.0
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 3.0.0
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: 4.0.0
67
+ - !ruby/object:Gem::Dependency
68
+ name: pry
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ description: Rails gem to treat DB functions, triggers, etc more like code, and make
82
+ them more discoverable
83
+ email:
84
+ - yeosuanaik@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - MIT-LICENSE
90
+ - README.md
91
+ - Rakefile
92
+ - lib/generators/obvious_data_directories_generator.rb
93
+ - lib/obvious_data.rb
94
+ - lib/obvious_data/command_recorder_methods.rb
95
+ - lib/obvious_data/railtie.rb
96
+ - lib/obvious_data/schema_methods.rb
97
+ - lib/obvious_data/version.rb
98
+ - lib/tasks/obvious_data_tasks.rake
99
+ - spec/dummy/README.rdoc
100
+ - spec/dummy/Rakefile
101
+ - spec/dummy/app/assets/javascripts/application.js
102
+ - spec/dummy/app/assets/stylesheets/application.css
103
+ - spec/dummy/app/controllers/application_controller.rb
104
+ - spec/dummy/app/helpers/application_helper.rb
105
+ - spec/dummy/app/views/layouts/application.html.erb
106
+ - spec/dummy/config.ru
107
+ - spec/dummy/config/application.rb
108
+ - spec/dummy/config/boot.rb
109
+ - spec/dummy/config/database.yml
110
+ - spec/dummy/config/environment.rb
111
+ - spec/dummy/config/environments/development.rb
112
+ - spec/dummy/config/environments/production.rb
113
+ - spec/dummy/config/environments/test.rb
114
+ - spec/dummy/config/initializers/backtrace_silencers.rb
115
+ - spec/dummy/config/initializers/inflections.rb
116
+ - spec/dummy/config/initializers/mime_types.rb
117
+ - spec/dummy/config/initializers/secret_token.rb
118
+ - spec/dummy/config/initializers/session_store.rb
119
+ - spec/dummy/config/initializers/wrap_parameters.rb
120
+ - spec/dummy/config/locales/en.yml
121
+ - spec/dummy/config/routes.rb
122
+ - spec/dummy/db/migrate/20140724185749_create_dummy_table.rb
123
+ - spec/dummy/db/migrate/20140724192457_create_dummy_trigger_func.rb
124
+ - spec/dummy/db/structure.sql
125
+ - spec/dummy/db/test.sqlite3
126
+ - spec/dummy/log/development.log
127
+ - spec/dummy/log/test.log
128
+ - spec/dummy/public/404.html
129
+ - spec/dummy/public/422.html
130
+ - spec/dummy/public/500.html
131
+ - spec/dummy/public/favicon.ico
132
+ - spec/dummy/script/rails
133
+ - spec/migrations_spec.rb
134
+ - spec/sanity_spec.rb
135
+ - spec/spec_helper.rb
136
+ - spec/support/db/functions/one.sql
137
+ - spec/support/db/triggers/one_t.sql
138
+ - spec/support/db/views/one_v.sql
139
+ homepage: http://github.com/enova/obvious_data
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.2.0
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Treat DB functions, triggers, etc more like code, and make them more discoverable
163
+ test_files:
164
+ - spec/dummy/app/assets/javascripts/application.js
165
+ - spec/dummy/app/assets/stylesheets/application.css
166
+ - spec/dummy/app/controllers/application_controller.rb
167
+ - spec/dummy/app/helpers/application_helper.rb
168
+ - spec/dummy/app/views/layouts/application.html.erb
169
+ - spec/dummy/config/application.rb
170
+ - spec/dummy/config/boot.rb
171
+ - spec/dummy/config/database.yml
172
+ - spec/dummy/config/environment.rb
173
+ - spec/dummy/config/environments/development.rb
174
+ - spec/dummy/config/environments/production.rb
175
+ - spec/dummy/config/environments/test.rb
176
+ - spec/dummy/config/initializers/backtrace_silencers.rb
177
+ - spec/dummy/config/initializers/inflections.rb
178
+ - spec/dummy/config/initializers/mime_types.rb
179
+ - spec/dummy/config/initializers/secret_token.rb
180
+ - spec/dummy/config/initializers/session_store.rb
181
+ - spec/dummy/config/initializers/wrap_parameters.rb
182
+ - spec/dummy/config/locales/en.yml
183
+ - spec/dummy/config/routes.rb
184
+ - spec/dummy/config.ru
185
+ - spec/dummy/db/migrate/20140724185749_create_dummy_table.rb
186
+ - spec/dummy/db/migrate/20140724192457_create_dummy_trigger_func.rb
187
+ - spec/dummy/db/structure.sql
188
+ - spec/dummy/db/test.sqlite3
189
+ - spec/dummy/log/development.log
190
+ - spec/dummy/log/test.log
191
+ - spec/dummy/public/404.html
192
+ - spec/dummy/public/422.html
193
+ - spec/dummy/public/500.html
194
+ - spec/dummy/public/favicon.ico
195
+ - spec/dummy/Rakefile
196
+ - spec/dummy/README.rdoc
197
+ - spec/dummy/script/rails
198
+ - spec/migrations_spec.rb
199
+ - spec/sanity_spec.rb
200
+ - spec/spec_helper.rb
201
+ - spec/support/db/functions/one.sql
202
+ - spec/support/db/triggers/one_t.sql
203
+ - spec/support/db/views/one_v.sql