rails_sql_views4 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +121 -0
  5. data/lib/active_record/view.rb +80 -0
  6. data/lib/core_ext/module.rb +13 -0
  7. data/lib/rails_sql_views4/connection_adapters/abstract/schema_definitions.rb +63 -0
  8. data/lib/rails_sql_views4/connection_adapters/abstract/schema_statements.rb +85 -0
  9. data/lib/rails_sql_views4/connection_adapters/abstract_adapter.rb +41 -0
  10. data/lib/rails_sql_views4/connection_adapters/mysql2_adapter.rb +66 -0
  11. data/lib/rails_sql_views4/connection_adapters/mysql_adapter.rb +66 -0
  12. data/lib/rails_sql_views4/connection_adapters/oci_adapter.rb +33 -0
  13. data/lib/rails_sql_views4/connection_adapters/oracle_adapter.rb +33 -0
  14. data/lib/rails_sql_views4/connection_adapters/oracleenhanced_adapter.rb +39 -0
  15. data/lib/rails_sql_views4/connection_adapters/oracleenhanced_adapter.rb.orig +72 -0
  16. data/lib/rails_sql_views4/connection_adapters/postgresql_adapter.rb +69 -0
  17. data/lib/rails_sql_views4/connection_adapters/postgresql_adapter.rb.orig +69 -0
  18. data/lib/rails_sql_views4/connection_adapters/sqlite3_adapter.rb +68 -0
  19. data/lib/rails_sql_views4/connection_adapters/sqlite_adapter.rb +68 -0
  20. data/lib/rails_sql_views4/connection_adapters/sqlserver_adapter.rb +43 -0
  21. data/lib/rails_sql_views4/loader.rb +18 -0
  22. data/lib/rails_sql_views4/schema_dumper.rb +114 -0
  23. data/lib/rails_sql_views4/version.rb +3 -0
  24. data/lib/rails_sql_views4.rb +28 -0
  25. data/lib/tasks/rails_sql_views4_tasks.rake +4 -0
  26. data/test/README.NOT_UP_TO_DATE +63 -0
  27. data/test/adapter_test.rb +93 -0
  28. data/test/connection/native_mysql/connection.rb +32 -0
  29. data/test/connection/native_mysql/schema.sql +34 -0
  30. data/test/connection/native_postgresql/connection.rb +31 -0
  31. data/test/connection/native_postgresql/schema.sql +33 -0
  32. data/test/connection/oracle_enhanced/connection.rb +29 -0
  33. data/test/connection/oracle_enhanced/procedures.sql +15 -0
  34. data/test/connection/oracle_enhanced/schema.sql +39 -0
  35. data/test/connection.example.yml +12 -0
  36. data/test/dummy/README.rdoc +28 -0
  37. data/test/dummy/Rakefile +6 -0
  38. data/test/dummy/app/assets/javascripts/application.js +13 -0
  39. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  40. data/test/dummy/app/controllers/application_controller.rb +5 -0
  41. data/test/dummy/app/helpers/application_helper.rb +2 -0
  42. data/test/dummy/app/models/item.rb +4 -0
  43. data/test/dummy/app/models/person.rb +5 -0
  44. data/test/dummy/app/models/person2.rb +4 -0
  45. data/test/dummy/app/models/place.rb +2 -0
  46. data/test/dummy/app/models/v_person.rb +8 -0
  47. data/test/dummy/app/models/v_profile.rb +3 -0
  48. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  49. data/test/dummy/bin/bundle +3 -0
  50. data/test/dummy/bin/rails +4 -0
  51. data/test/dummy/bin/rake +4 -0
  52. data/test/dummy/config/application.rb +23 -0
  53. data/test/dummy/config/boot.rb +5 -0
  54. data/test/dummy/config/database.yml +25 -0
  55. data/test/dummy/config/environment.rb +5 -0
  56. data/test/dummy/config/environments/development.rb +37 -0
  57. data/test/dummy/config/environments/production.rb +78 -0
  58. data/test/dummy/config/environments/test.rb +39 -0
  59. data/test/dummy/config/initializers/assets.rb +8 -0
  60. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  61. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  62. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  63. data/test/dummy/config/initializers/inflections.rb +16 -0
  64. data/test/dummy/config/initializers/mime_types.rb +4 -0
  65. data/test/dummy/config/initializers/session_store.rb +3 -0
  66. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  67. data/test/dummy/config/locales/en.yml +23 -0
  68. data/test/dummy/config/routes.rb +56 -0
  69. data/test/dummy/config/secrets.yml +22 -0
  70. data/test/dummy/config.ru +4 -0
  71. data/test/dummy/db/development.sqlite3 +0 -0
  72. data/test/dummy/db/migrate/20141228200436_create_people.rb +10 -0
  73. data/test/dummy/db/migrate/20141228200437_create_people2.rb +11 -0
  74. data/test/dummy/db/migrate/20141228200438_create_places.rb +12 -0
  75. data/test/dummy/db/migrate/20141228200439_create_items.rb +8 -0
  76. data/test/dummy/db/migrate/20141228200440_create_items_people.rb +9 -0
  77. data/test/dummy/db/schema.rb +53 -0
  78. data/test/dummy/db/test.sqlite3 +0 -0
  79. data/test/dummy/log/development.log +439 -0
  80. data/test/dummy/log/test.log +29320 -0
  81. data/test/dummy/public/404.html +67 -0
  82. data/test/dummy/public/422.html +67 -0
  83. data/test/dummy/public/500.html +66 -0
  84. data/test/dummy/public/favicon.ico +0 -0
  85. data/test/dummy/test/fixtures/persons.yml +7 -0
  86. data/test/dummy/test/models/person_test.rb +7 -0
  87. data/test/rails_sql_views4_test.rb +11 -0
  88. data/test/schema.native_mysql.expected.rb +51 -0
  89. data/test/schema.native_postgresql.expected.rb +51 -0
  90. data/test/schema.native_postgresql.out.rb +69 -0
  91. data/test/schema.oracle_enhanced.expected.rb +51 -0
  92. data/test/schema_dumper_test.rb +134 -0
  93. data/test/test_helper.rb +41 -0
  94. data/test/test_helper.rb.old +30 -0
  95. data/test/view_model_test.rb +68 -0
  96. data/test/view_operations_test.rb +50 -0
  97. metadata +225 -0
@@ -0,0 +1,68 @@
1
+ require 'test_helper'
2
+
3
+ # require 'models/item'
4
+ # require 'models/place'
5
+
6
+ class ViewModelTest < ActiveSupport::TestCase
7
+
8
+ def setup
9
+ create_people_view
10
+ VPerson.send(:based_on, Person)
11
+
12
+ @address = Place.create!
13
+ @person = Person.create!(:first_name => 'Primus', :address => @address)
14
+ @items = [ @person.owned_items.create!, @person.owned_items.create! ]
15
+ @sharable_items = [ Item.create!, Item.create!, Item.create! ]
16
+ @person.shared_items << @sharable_items[0]
17
+ @person.shared_items << @sharable_items[2]
18
+
19
+ @vperson = VPerson.find(@person.id)
20
+ end
21
+
22
+ def cleanup
23
+ Item.delete_all
24
+ Person.delete_all
25
+ Place.delete_all
26
+ end
27
+
28
+ def test_same_person
29
+ assert_equal @person.id, @vperson.id
30
+ end
31
+
32
+ def test_cloned_belongs_to_association_exists
33
+ reflection = VPerson.reflect_on_association(:address)
34
+ assert_not_nil reflection
35
+ end
36
+
37
+ test "access cloned belongs to association" do
38
+ # TODO ? Pas sur d'avoir compris
39
+ # Le modèle VPerson ne peut pas savoir qu'il a une association "belongs" si elle n'est pas déclarée.
40
+ # Voir le model VPerson, dans dummy
41
+ assert_equal @address, @vperson.address
42
+ end
43
+
44
+ def test_cloned_has_many_association_exists
45
+ reflection = VPerson.reflect_on_association(:owned_items)
46
+ assert_not_nil reflection
47
+ end
48
+
49
+ def test_access_cloned_has_many_association
50
+ items = @vperson.owned_items
51
+ assert_equal 2, items.size
52
+ assert_equal @items.sort_by(&:id), items.sort_by(&:id)
53
+ end
54
+
55
+ def test_cloned_habtm_association_exists
56
+ reflection = VPerson.reflect_on_association(:shared_items)
57
+ assert_not_nil reflection
58
+ end
59
+
60
+ # TODO ...
61
+
62
+ # def test_access_cloned_habtm_association
63
+ # items = @vperson.shared_items
64
+ # assert_equal 2, items.size
65
+ # expected_items = [ @sharable_items[0], @sharable_items[2] ]
66
+ # assert_equal expected_items.sort_by(&:id), items.sort_by(&:id)
67
+ # end
68
+ end
@@ -0,0 +1,50 @@
1
+ require 'test_helper'
2
+
3
+ class ViewOperationsTest < ActiveSupport::TestCase
4
+
5
+ def test_create_view
6
+ # Look at Dummy for app, Model, migration, etc ...
7
+
8
+ Person.create(:first_name => 'John', :last_name => 'Doe', :ssn => '123456789')
9
+
10
+ assert_nothing_raised do
11
+ # I DONT UNDERSTANT the "do" : xxx.create_view() do ?
12
+ # create_view return a empty array
13
+ ActiveRecord::Base.connection.create_view(:v_people,
14
+ # 'select first_name, last_name, ssn from people', :force => true) do |v|
15
+ 'select id, first_name, last_name, ssn from people', :force => true) do |v|
16
+ v.column :id # ID est obligatoire ?
17
+ v.column :f_name
18
+ v.column :l_name
19
+ v.column :social_security
20
+ end
21
+ end
22
+ # p = Person.find(:first) # rails 3
23
+ p = Person.first
24
+ # vp = VPerson.find(:first)
25
+ vp = VPerson.first
26
+ # assert_equal p.first_name, vp.f_name
27
+ assert_equal p.first_name, vp.first_name
28
+ end
29
+
30
+ def test_drop_view
31
+ assert_nothing_raised do
32
+ ActiveRecord::Base.connection.create_view(:v_place,
33
+ 'select address, city, cstate, country from places', :force => true) do |v|
34
+ v.column :v_address
35
+ v.column :v_city
36
+ v.column :v_state
37
+ v.column :v_country
38
+ end
39
+ ActiveRecord::Base.connection.drop_view(:v_place)
40
+ end
41
+ assert_raises(ActiveRecord::StatementInvalid) do
42
+ ActiveRecord::Base.connection.execute "SELECT * FROM v_place"
43
+ end
44
+ end
45
+
46
+ # TODO
47
+ def test_no_view_raises_error
48
+ assert_raises(RuntimeError) { ActiveRecord::Base.connection.view_select_statement('foo') }
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,225 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_sql_views4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Laurent Buffat, adapted from rails_sql_view, by Anthony Eden
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-04 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: 4.2.O.rc3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.O.rc3
27
+ description: 'RailsSqlView4 : uptated version of RailsSqlView : Adds support for using
28
+ SQL views within ActiveRecord'
29
+ email:
30
+ - laurent.buffat@altrabio.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - MIT-LICENSE
36
+ - README.rdoc
37
+ - Rakefile
38
+ - lib/active_record/view.rb
39
+ - lib/core_ext/module.rb
40
+ - lib/rails_sql_views4.rb
41
+ - lib/rails_sql_views4/connection_adapters/abstract/schema_definitions.rb
42
+ - lib/rails_sql_views4/connection_adapters/abstract/schema_statements.rb
43
+ - lib/rails_sql_views4/connection_adapters/abstract_adapter.rb
44
+ - lib/rails_sql_views4/connection_adapters/mysql2_adapter.rb
45
+ - lib/rails_sql_views4/connection_adapters/mysql_adapter.rb
46
+ - lib/rails_sql_views4/connection_adapters/oci_adapter.rb
47
+ - lib/rails_sql_views4/connection_adapters/oracle_adapter.rb
48
+ - lib/rails_sql_views4/connection_adapters/oracleenhanced_adapter.rb
49
+ - lib/rails_sql_views4/connection_adapters/oracleenhanced_adapter.rb.orig
50
+ - lib/rails_sql_views4/connection_adapters/postgresql_adapter.rb
51
+ - lib/rails_sql_views4/connection_adapters/postgresql_adapter.rb.orig
52
+ - lib/rails_sql_views4/connection_adapters/sqlite3_adapter.rb
53
+ - lib/rails_sql_views4/connection_adapters/sqlite_adapter.rb
54
+ - lib/rails_sql_views4/connection_adapters/sqlserver_adapter.rb
55
+ - lib/rails_sql_views4/loader.rb
56
+ - lib/rails_sql_views4/schema_dumper.rb
57
+ - lib/rails_sql_views4/version.rb
58
+ - lib/tasks/rails_sql_views4_tasks.rake
59
+ - test/README.NOT_UP_TO_DATE
60
+ - test/adapter_test.rb
61
+ - test/connection.example.yml
62
+ - test/connection/native_mysql/connection.rb
63
+ - test/connection/native_mysql/schema.sql
64
+ - test/connection/native_postgresql/connection.rb
65
+ - test/connection/native_postgresql/schema.sql
66
+ - test/connection/oracle_enhanced/connection.rb
67
+ - test/connection/oracle_enhanced/procedures.sql
68
+ - test/connection/oracle_enhanced/schema.sql
69
+ - test/dummy/README.rdoc
70
+ - test/dummy/Rakefile
71
+ - test/dummy/app/assets/javascripts/application.js
72
+ - test/dummy/app/assets/stylesheets/application.css
73
+ - test/dummy/app/controllers/application_controller.rb
74
+ - test/dummy/app/helpers/application_helper.rb
75
+ - test/dummy/app/models/item.rb
76
+ - test/dummy/app/models/person.rb
77
+ - test/dummy/app/models/person2.rb
78
+ - test/dummy/app/models/place.rb
79
+ - test/dummy/app/models/v_person.rb
80
+ - test/dummy/app/models/v_profile.rb
81
+ - test/dummy/app/views/layouts/application.html.erb
82
+ - test/dummy/bin/bundle
83
+ - test/dummy/bin/rails
84
+ - test/dummy/bin/rake
85
+ - test/dummy/config.ru
86
+ - test/dummy/config/application.rb
87
+ - test/dummy/config/boot.rb
88
+ - test/dummy/config/database.yml
89
+ - test/dummy/config/environment.rb
90
+ - test/dummy/config/environments/development.rb
91
+ - test/dummy/config/environments/production.rb
92
+ - test/dummy/config/environments/test.rb
93
+ - test/dummy/config/initializers/assets.rb
94
+ - test/dummy/config/initializers/backtrace_silencers.rb
95
+ - test/dummy/config/initializers/cookies_serializer.rb
96
+ - test/dummy/config/initializers/filter_parameter_logging.rb
97
+ - test/dummy/config/initializers/inflections.rb
98
+ - test/dummy/config/initializers/mime_types.rb
99
+ - test/dummy/config/initializers/session_store.rb
100
+ - test/dummy/config/initializers/wrap_parameters.rb
101
+ - test/dummy/config/locales/en.yml
102
+ - test/dummy/config/routes.rb
103
+ - test/dummy/config/secrets.yml
104
+ - test/dummy/db/development.sqlite3
105
+ - test/dummy/db/migrate/20141228200436_create_people.rb
106
+ - test/dummy/db/migrate/20141228200437_create_people2.rb
107
+ - test/dummy/db/migrate/20141228200438_create_places.rb
108
+ - test/dummy/db/migrate/20141228200439_create_items.rb
109
+ - test/dummy/db/migrate/20141228200440_create_items_people.rb
110
+ - test/dummy/db/schema.rb
111
+ - test/dummy/db/test.sqlite3
112
+ - test/dummy/log/development.log
113
+ - test/dummy/log/test.log
114
+ - test/dummy/public/404.html
115
+ - test/dummy/public/422.html
116
+ - test/dummy/public/500.html
117
+ - test/dummy/public/favicon.ico
118
+ - test/dummy/test/fixtures/persons.yml
119
+ - test/dummy/test/models/person_test.rb
120
+ - test/rails_sql_views4_test.rb
121
+ - test/schema.native_mysql.expected.rb
122
+ - test/schema.native_postgresql.expected.rb
123
+ - test/schema.native_postgresql.out.rb
124
+ - test/schema.oracle_enhanced.expected.rb
125
+ - test/schema_dumper_test.rb
126
+ - test/test_helper.rb
127
+ - test/test_helper.rb.old
128
+ - test/view_model_test.rb
129
+ - test/view_operations_test.rb
130
+ homepage: http://activewarehouse.rubyforge.org/rails_sql_views4
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.4.4
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: 'Summary of RailsSqlViews4 : A DRAFT for RailsSqlView adapted for Rails 4'
154
+ test_files:
155
+ - test/adapter_test.rb
156
+ - test/connection/native_mysql/connection.rb
157
+ - test/connection/native_mysql/schema.sql
158
+ - test/connection/native_postgresql/connection.rb
159
+ - test/connection/native_postgresql/schema.sql
160
+ - test/connection/oracle_enhanced/connection.rb
161
+ - test/connection/oracle_enhanced/procedures.sql
162
+ - test/connection/oracle_enhanced/schema.sql
163
+ - test/connection.example.yml
164
+ - test/dummy/app/assets/javascripts/application.js
165
+ - test/dummy/app/assets/stylesheets/application.css
166
+ - test/dummy/app/controllers/application_controller.rb
167
+ - test/dummy/app/helpers/application_helper.rb
168
+ - test/dummy/app/models/item.rb
169
+ - test/dummy/app/models/person.rb
170
+ - test/dummy/app/models/person2.rb
171
+ - test/dummy/app/models/place.rb
172
+ - test/dummy/app/models/v_person.rb
173
+ - test/dummy/app/models/v_profile.rb
174
+ - test/dummy/app/views/layouts/application.html.erb
175
+ - test/dummy/bin/bundle
176
+ - test/dummy/bin/rails
177
+ - test/dummy/bin/rake
178
+ - test/dummy/config/application.rb
179
+ - test/dummy/config/boot.rb
180
+ - test/dummy/config/database.yml
181
+ - test/dummy/config/environment.rb
182
+ - test/dummy/config/environments/development.rb
183
+ - test/dummy/config/environments/production.rb
184
+ - test/dummy/config/environments/test.rb
185
+ - test/dummy/config/initializers/assets.rb
186
+ - test/dummy/config/initializers/backtrace_silencers.rb
187
+ - test/dummy/config/initializers/cookies_serializer.rb
188
+ - test/dummy/config/initializers/filter_parameter_logging.rb
189
+ - test/dummy/config/initializers/inflections.rb
190
+ - test/dummy/config/initializers/mime_types.rb
191
+ - test/dummy/config/initializers/session_store.rb
192
+ - test/dummy/config/initializers/wrap_parameters.rb
193
+ - test/dummy/config/locales/en.yml
194
+ - test/dummy/config/routes.rb
195
+ - test/dummy/config/secrets.yml
196
+ - test/dummy/config.ru
197
+ - test/dummy/db/development.sqlite3
198
+ - test/dummy/db/migrate/20141228200436_create_people.rb
199
+ - test/dummy/db/migrate/20141228200437_create_people2.rb
200
+ - test/dummy/db/migrate/20141228200438_create_places.rb
201
+ - test/dummy/db/migrate/20141228200439_create_items.rb
202
+ - test/dummy/db/migrate/20141228200440_create_items_people.rb
203
+ - test/dummy/db/schema.rb
204
+ - test/dummy/db/test.sqlite3
205
+ - test/dummy/log/development.log
206
+ - test/dummy/log/test.log
207
+ - test/dummy/public/404.html
208
+ - test/dummy/public/422.html
209
+ - test/dummy/public/500.html
210
+ - test/dummy/public/favicon.ico
211
+ - test/dummy/Rakefile
212
+ - test/dummy/README.rdoc
213
+ - test/dummy/test/fixtures/persons.yml
214
+ - test/dummy/test/models/person_test.rb
215
+ - test/rails_sql_views4_test.rb
216
+ - test/README.NOT_UP_TO_DATE
217
+ - test/schema.native_mysql.expected.rb
218
+ - test/schema.native_postgresql.expected.rb
219
+ - test/schema.native_postgresql.out.rb
220
+ - test/schema.oracle_enhanced.expected.rb
221
+ - test/schema_dumper_test.rb
222
+ - test/test_helper.rb
223
+ - test/test_helper.rb.old
224
+ - test/view_model_test.rb
225
+ - test/view_operations_test.rb