marty 0.5.15 → 0.5.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +27 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +23 -0
  5. data/Gemfile +23 -0
  6. data/INDEPENDENCE_ISSUES.md +23 -0
  7. data/app/assets/images/marty/.gitkeep +0 -0
  8. data/app/components/marty/report_form.rb +9 -4
  9. data/gemini_deprecations.md +6 -0
  10. data/lib/marty/data_change.rb +99 -0
  11. data/lib/marty/data_conversion.rb +11 -3
  12. data/lib/marty/data_exporter.rb +9 -0
  13. data/lib/marty/version.rb +1 -1
  14. data/marty.gemspec +35 -0
  15. data/script/rails +8 -0
  16. data/spec/controllers/application_controller_spec.rb +52 -0
  17. data/spec/controllers/job_controller_spec.rb +226 -0
  18. data/spec/controllers/rpc_controller_spec.rb +379 -0
  19. data/spec/controllers/rpc_import_spec.rb +45 -0
  20. data/spec/dummy/README.rdoc +261 -0
  21. data/spec/dummy/Rakefile +7 -0
  22. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  23. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  24. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  25. data/spec/dummy/app/controllers/components_controller.rb +7 -0
  26. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  27. data/spec/dummy/app/mailers/.gitkeep +0 -0
  28. data/spec/dummy/app/models/.gitkeep +0 -0
  29. data/spec/dummy/app/models/gemini/amortization_type.rb +5 -0
  30. data/spec/dummy/app/models/gemini/bud_category.rb +7 -0
  31. data/spec/dummy/app/models/gemini/entity.rb +2 -0
  32. data/spec/dummy/app/models/gemini/extras/data_import.rb +5 -0
  33. data/spec/dummy/app/models/gemini/extras/settlement_import.rb +28 -0
  34. data/spec/dummy/app/models/gemini/fannie_bup.rb +29 -0
  35. data/spec/dummy/app/models/gemini/grouping.rb +8 -0
  36. data/spec/dummy/app/models/gemini/grouping_head_version.rb +14 -0
  37. data/spec/dummy/app/models/gemini/head.rb +7 -0
  38. data/spec/dummy/app/models/gemini/head_version.rb +14 -0
  39. data/spec/dummy/app/models/gemini/helper.rb +44 -0
  40. data/spec/dummy/app/models/gemini/loan_program.rb +11 -0
  41. data/spec/dummy/app/models/gemini/mortgage_type.rb +5 -0
  42. data/spec/dummy/app/models/gemini/simple.rb +6 -0
  43. data/spec/dummy/app/models/gemini/streamline_type.rb +16 -0
  44. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  45. data/spec/dummy/config.ru +4 -0
  46. data/spec/dummy/config/application.rb +82 -0
  47. data/spec/dummy/config/boot.rb +10 -0
  48. data/spec/dummy/config/database.yml.example +10 -0
  49. data/spec/dummy/config/environment.rb +5 -0
  50. data/spec/dummy/config/environments/development.rb +35 -0
  51. data/spec/dummy/config/environments/production.rb +69 -0
  52. data/spec/dummy/config/environments/test.rb +39 -0
  53. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  54. data/spec/dummy/config/initializers/delayed_job.rb +5 -0
  55. data/spec/dummy/config/initializers/inflections.rb +15 -0
  56. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  57. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  58. data/spec/dummy/config/initializers/session_store.rb +8 -0
  59. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  60. data/spec/dummy/config/locales/en.yml +5 -0
  61. data/spec/dummy/config/routes.rb +12 -0
  62. data/spec/dummy/db/migrate/20140801000000_create_groupings.rb +11 -0
  63. data/spec/dummy/db/migrate/20150406171536_create_categories.rb +27 -0
  64. data/spec/dummy/db/migrate/20150408200916_create_loan_programs.rb +26 -0
  65. data/spec/dummy/db/migrate/20150408201429_create_types.rb +21 -0
  66. data/spec/dummy/db/migrate/20150420000001_create_heads.rb +14 -0
  67. data/spec/dummy/db/migrate/20150420000002_create_head_versions.rb +15 -0
  68. data/spec/dummy/db/migrate/20150420000003_create_grouping_head_versions.rb +12 -0
  69. data/spec/dummy/db/migrate/20151023000001_create_simple.rb +12 -0
  70. data/spec/dummy/db/seeds.rb +8 -0
  71. data/spec/dummy/delorean/blame_report.dl +171 -0
  72. data/spec/dummy/delorean/data_report.dl +105 -0
  73. data/spec/dummy/delorean/fields.dl +52 -0
  74. data/spec/dummy/delorean/styles.dl +134 -0
  75. data/spec/dummy/lib/assets/.gitkeep +0 -0
  76. data/spec/dummy/lib/class_list.rb +3 -0
  77. data/spec/dummy/log/.gitkeep +0 -0
  78. data/spec/dummy/public/404.html +26 -0
  79. data/spec/dummy/public/422.html +26 -0
  80. data/spec/dummy/public/500.html +25 -0
  81. data/spec/dummy/public/favicon.ico +0 -0
  82. data/spec/dummy/public/icons/READ.txt +3 -0
  83. data/spec/dummy/public/icons/application_cascade.png +0 -0
  84. data/spec/dummy/public/icons/application_delete.png +0 -0
  85. data/spec/dummy/public/icons/application_put.png +0 -0
  86. data/spec/dummy/public/icons/application_view_detail.png +0 -0
  87. data/spec/dummy/public/icons/arrow_in.png +0 -0
  88. data/spec/dummy/public/icons/arrow_refresh.png +0 -0
  89. data/spec/dummy/public/icons/database_save.png +0 -0
  90. data/spec/dummy/public/icons/door_in.png +0 -0
  91. data/spec/dummy/public/icons/door_out.png +0 -0
  92. data/spec/dummy/public/icons/group.png +0 -0
  93. data/spec/dummy/public/icons/page_lightning.png +0 -0
  94. data/spec/dummy/public/icons/printer.png +0 -0
  95. data/spec/dummy/public/icons/report_disk.png +0 -0
  96. data/spec/dummy/public/icons/report_go.png +0 -0
  97. data/spec/dummy/public/icons/report_magnify.png +0 -0
  98. data/spec/dummy/public/icons/script.png +0 -0
  99. data/spec/dummy/public/icons/script_add.png +0 -0
  100. data/spec/dummy/public/icons/script_go.png +0 -0
  101. data/spec/dummy/public/icons/script_key.png +0 -0
  102. data/spec/dummy/public/icons/table_go.png +0 -0
  103. data/spec/dummy/public/icons/time.png +0 -0
  104. data/spec/dummy/public/icons/time_add.png +0 -0
  105. data/spec/dummy/public/icons/time_go.png +0 -0
  106. data/spec/dummy/public/icons/timeline_marker.png +0 -0
  107. data/spec/dummy/public/icons/user_add.png +0 -0
  108. data/spec/dummy/public/icons/user_delete.png +0 -0
  109. data/spec/dummy/public/icons/user_edit.png +0 -0
  110. data/spec/dummy/public/icons/wrench.png +0 -0
  111. data/spec/dummy/script/delayed_job +6 -0
  112. data/spec/dummy/script/rails +6 -0
  113. data/spec/features/javascripts/job_dashboard_live_search.js.coffee +8 -0
  114. data/spec/features/javascripts/login.js.coffee +8 -0
  115. data/spec/features/jobs_dashboard_netzke_spec.rb +24 -0
  116. data/spec/features/jobs_dashboard_spec.rb +49 -0
  117. data/spec/fixtures/scripts/load_tests/script1.dl +2 -0
  118. data/spec/fixtures/scripts/load_tests/script2.dl +2 -0
  119. data/spec/job_helper.rb +102 -0
  120. data/spec/lib/data_exporter_spec.rb +71 -0
  121. data/spec/lib/data_importer_spec.rb +461 -0
  122. data/spec/lib/xl_spec.rb +198 -0
  123. data/spec/lib/xl_styles_spec.rb +115 -0
  124. data/spec/models/api_auth_spec.rb +187 -0
  125. data/spec/models/posting_spec.rb +107 -0
  126. data/spec/models/promise_spec.rb +65 -0
  127. data/spec/models/script_spec.rb +187 -0
  128. data/spec/models/user_spec.rb +68 -0
  129. data/spec/requests/routes_spec.rb +12 -0
  130. data/spec/spec_helper.rb +61 -0
  131. data/spec/support/clean_db_helpers.rb +18 -0
  132. data/spec/support/delayed_job_helpers.rb +12 -0
  133. data/spec/support/user_helpers.rb +12 -0
  134. metadata +139 -89
  135. data/app/components/marty/auth_app.rb~ +0 -51
  136. data/app/components/marty/auth_app/javascripts/auth_app.js~ +0 -91
  137. data/app/components/marty/cm_form_panel.rb~ +0 -5
  138. data/app/components/marty/cm_grid_panel.rb~ +0 -35
  139. data/app/components/marty/data_import_view.rb~ +0 -142
  140. data/app/components/marty/extras/layout.rb~ +0 -46
  141. data/app/components/marty/live_search_grid_panel.rb~ +0 -49
  142. data/app/components/marty/main_auth_app.rb~ +0 -238
  143. data/app/components/marty/mcfly_grid_panel.rb~ +0 -80
  144. data/app/components/marty/new_posting_form.rb~ +0 -46
  145. data/app/components/marty/new_posting_window.rb~ +0 -21
  146. data/app/components/marty/pivot_grid.rb +0 -52
  147. data/app/components/marty/pivot_grid/endpoints.rb +0 -45
  148. data/app/components/marty/pivot_grid/javascripts/extensions.js +0 -150
  149. data/app/components/marty/pivot_grid/javascripts/pivot_grid.js +0 -86
  150. data/app/components/marty/pivot_grid/services.rb +0 -44
  151. data/app/components/marty/posting_grid.rb~ +0 -140
  152. data/app/components/marty/promise_view.rb~ +0 -157
  153. data/app/components/marty/promise_view/stylesheets/promise_view.css~ +0 -15
  154. data/app/components/marty/report_form.rb~ +0 -217
  155. data/app/components/marty/report_select.rb~ +0 -133
  156. data/app/components/marty/reporting.rb~ +0 -39
  157. data/app/components/marty/script_detail.rb~ +0 -430
  158. data/app/components/marty/script_form.rb~ +0 -233
  159. data/app/components/marty/script_form/javascripts/Ext.ux.form.field.CodeMirror.js~ +0 -909
  160. data/app/components/marty/script_grid.rb~ +0 -99
  161. data/app/components/marty/script_tester.rb~ +0 -213
  162. data/app/components/marty/scripting.rb~ +0 -124
  163. data/app/components/marty/select_report.rb~ +0 -143
  164. data/app/components/marty/simple_app.rb~ +0 -101
  165. data/app/components/marty/tag_grid.rb~ +0 -89
  166. data/app/components/marty/tree_panel.rb~ +0 -256
  167. data/app/components/marty/tree_panel/javascripts/tree_panel.js~ +0 -317
  168. data/app/components/marty/user_pivot.rb +0 -128
  169. data/app/components/marty/user_view.rb~ +0 -188
  170. data/app/controllers/marty/application_controller.rb~ +0 -133
  171. data/app/controllers/marty/components_controller.rb~ +0 -37
  172. data/app/controllers/marty/job_controller.rb~ +0 -28
  173. data/app/controllers/marty/rpc_controller.rb~ +0 -61
  174. data/app/helpers/marty/script_set.rb~ +0 -59
  175. data/app/models/marty/api_auth.rb~ +0 -48
  176. data/app/models/marty/data_change.rb~ +0 -141
  177. data/app/models/marty/enum.rb~ +0 -16
  178. data/app/models/marty/import_type.rb~ +0 -48
  179. data/app/models/marty/poop.rb~ +0 -169
  180. data/app/models/marty/posting.rb~ +0 -86
  181. data/app/models/marty/posting_type.rb~ +0 -21
  182. data/app/models/marty/promise.rb~ +0 -196
  183. data/app/models/marty/role.rb~ +0 -10
  184. data/app/models/marty/script.rb~ +0 -62
  185. data/app/models/marty/tag.rb~ +0 -91
  186. data/app/models/marty/user.rb~ +0 -148
  187. data/app/models/marty/user_role.rb~ +0 -13
  188. data/app/views/layouts/marty/application.html.erb~ +0 -11
  189. data/config/routes.rb~ +0 -10
  190. data/db/migrate/019_create_marty_postings.rb~ +0 -19
  191. data/db/migrate/095_create_marty_tags.rb~ +0 -19
  192. data/lib/marty.rb~ +0 -13
  193. data/lib/marty/content_handler.rb~ +0 -93
  194. data/lib/marty/data_exporter.rb~ +0 -137
  195. data/lib/marty/data_importer.rb~ +0 -114
  196. data/lib/marty/data_row_processor.rb~ +0 -206
  197. data/lib/marty/drop_folder_hook.rb~ +0 -17
  198. data/lib/marty/folder_hook.rb~ +0 -9
  199. data/lib/marty/lazy_column_loader.rb~ +0 -47
  200. data/lib/marty/mcfly_query.rb~ +0 -188
  201. data/lib/marty/migrations.rb~ +0 -65
  202. data/lib/marty/monkey.rb~ +0 -160
  203. data/lib/marty/permissions.rb~ +0 -69
  204. data/lib/marty/promise.rb~ +0 -41
  205. data/lib/marty/promise_job.rb~ +0 -121
  206. data/lib/marty/promise_proxy.rb~ +0 -69
  207. data/lib/marty/util.rb~ +0 -80
  208. data/lib/marty/version.rb~ +0 -3
  209. data/lib/marty/xl.rb~ +0 -526
  210. data/lib/pyxll/README.txt~ +0 -16
  211. data/lib/pyxll/gemini.py~ +0 -110
  212. data/lib/pyxll/pyxll.cfg~ +0 -12
@@ -0,0 +1,379 @@
1
+ require 'spec_helper'
2
+
3
+ sample_script = <<DELOREAN
4
+ A:
5
+ a =? 123.0
6
+ b = a * 3
7
+
8
+ B: A
9
+ c = a + b
10
+ d =?
11
+ e = c / a
12
+ f = e * d
13
+
14
+ C:
15
+ p0 =?
16
+ a = 456.0 + p0
17
+
18
+ D:
19
+ in =? "no input"
20
+ out = in
21
+
22
+ DELOREAN
23
+
24
+ sample_script3 = <<eof
25
+ A:
26
+ a = 2
27
+ p =?
28
+ c = a * 2
29
+ pc = p + c
30
+ lc = [pc, pc]
31
+
32
+ C: A
33
+ p =? 3
34
+
35
+ B: A
36
+ p =? 5
37
+ eof
38
+
39
+ sample_script4 = <<eof
40
+ import M3
41
+ A: M3::A
42
+ p =? 10
43
+ c = a * 2
44
+ d = pc - 1
45
+ result = [{"a": 123, "b": 456}, {"a": 789, "b": 101112}]
46
+ eof
47
+
48
+ describe Marty::RpcController do
49
+ before(:each) {
50
+ @routes = Marty::Engine.routes
51
+
52
+ # HACKY: 'params' param is special to the Rails controller test helper (at
53
+ # least as of 4.2). Setting this avoids test framework code that relies on
54
+ # params being a hash.
55
+ @request.env['PATH_INFO'] = "/marty/rpc/evaluate.json"
56
+ }
57
+
58
+ before(:each) {
59
+ @p0 = Marty::Posting.do_create("BASE", Date.today, 'a comment')
60
+
61
+ @t1 = Marty::Script.load_script_bodies({
62
+ "M1" => sample_script,
63
+ "M2" => sample_script.gsub(/a/, "aa").gsub(/b/, "bb"),
64
+ "M3" => sample_script3,
65
+ "M4" => sample_script4,
66
+ }, Date.today + 1.minute)
67
+
68
+ @p1 = Marty::Posting.do_create("BASE", Date.today + 2.minute, 'a comment')
69
+
70
+ @t2 = Marty::Script.load_script_bodies({
71
+ "M1" =>
72
+ sample_script.gsub(/A/, "AA")+' e =? "hello"',
73
+ }, Date.today + 3.minute)
74
+
75
+ @p2 = Marty::Posting.do_create("BASE", Date.today + 4.minute, 'a comment')
76
+ @data = [["some data",7,[1,2,3],{foo: "bar", baz: "quz"},5,"string"],
77
+ ["some more data",[1,2,3],5,{foo: "bar", baz: "quz"},5,"string"]]
78
+ @data_json = [@data].to_json
79
+ }
80
+
81
+ let(:t1) { @t1 }
82
+ let(:t2) { @t2 }
83
+ let(:p0) { @p0 }
84
+ let(:p1) { @p1 }
85
+ let(:p2) { @p2 }
86
+
87
+ it "should be able to post" do
88
+ post 'evaluate', {
89
+ format: :json,
90
+ script: "M1",
91
+ node: "B",
92
+ attrs: ["e","f"].to_json,
93
+ tag: t1.name,
94
+ params: { a: 333, d: 5}.to_json
95
+ }
96
+ expect(response.body).to eq([4,20].to_json)
97
+ end
98
+ it "should be able to post with complex data" do
99
+ post 'evaluate', {
100
+ format: :json,
101
+ script: "M1",
102
+ node: "D",
103
+ attrs: ["out"].to_json,
104
+ tag: t1.name,
105
+ params: {in: @data}.to_json
106
+ }
107
+ expect(response.body).to eq(@data_json)
108
+ end
109
+ # content-type: application/json structures the request a little differently
110
+ # so we also test that
111
+ it "should be able to post (JSON) with complex data" do
112
+ @request.env['CONTENT_TYPE'] = 'application/json'
113
+ @request.env['ACCEPT'] = 'application/json'
114
+ post 'evaluate', {
115
+ format: :json,
116
+ script: "M1",
117
+ node: "D",
118
+ attrs: ["out"].to_json,
119
+ tag: t1.name,
120
+ params: {in: @data}.to_json
121
+ }
122
+ expect(response.body).to eq(@data_json)
123
+ end
124
+ it "should be able to run scripts" do
125
+ get 'evaluate', {
126
+ format: :json,
127
+ script: "M1",
128
+ node: "A",
129
+ attrs: ["a", "b"].to_json,
130
+ tag: t1.name,
131
+ }
132
+ # puts 'Z'*40, request.inspect
133
+ expect(response.body).to eq([123.0, 369.0].to_json)
134
+
135
+ get 'evaluate', {
136
+ format: :json,
137
+ script: "M1",
138
+ node: "A",
139
+ attrs: ["a", "b"].to_json,
140
+ params: {"a" => 4.5}.to_json,
141
+ tag: t1.name,
142
+ }
143
+ expect(response.body).to eq([4.5,13.5].to_json)
144
+
145
+ get 'evaluate', {
146
+ format: :json,
147
+ script: "M1",
148
+ node: "B",
149
+ attrs: ["a", "b", "c"].to_json,
150
+ params: {"a" => 4.5}.to_json,
151
+ tag: t1.name,
152
+ }
153
+ expect(response.body).to eq([4.5, 13.5, 18.0].to_json)
154
+
155
+ get 'evaluate', {
156
+ format: :json,
157
+ script: "M1",
158
+ tag: "DEV",
159
+ node: "AA",
160
+ attrs: ["a", "b"].to_json,
161
+ params: {"a" => 3.3}.to_json,
162
+ }
163
+ res = ActiveSupport::JSON.decode(response.body).flatten.map{|x| x.round(8)}
164
+ expect(res).to eq([3.3, 9.9])
165
+ end
166
+
167
+ it "should be able to use posting name for tags" do
168
+ get 'evaluate', {
169
+ format: :json,
170
+ script: "M1",
171
+ node: "A",
172
+ attrs: ["a", "b"].to_json,
173
+ tag: p0.name,
174
+ }
175
+ expect(response.body["error"]).to_not be_nil
176
+
177
+ get 'evaluate', {
178
+ format: :json,
179
+ script: "M1",
180
+ node: "A",
181
+ attrs: ["a", "b"].to_json,
182
+ params: {"a" => 4.5}.to_json,
183
+ tag: p1.name,
184
+ }
185
+ expect(response.body).to eq([4.5,13.5].to_json)
186
+
187
+ get 'evaluate', {
188
+ format: :json,
189
+ script: "M1",
190
+ node: "B",
191
+ attrs: ["a", "b", "c"].to_json,
192
+ params: {"a" => 4.5}.to_json,
193
+ tag: p2.name,
194
+ }
195
+ expect(response.body).to eq([4.5, 13.5, 18.0].to_json)
196
+
197
+ get 'evaluate', {
198
+ format: :json,
199
+ script: "M1",
200
+ tag: "NOW",
201
+ node: "AA",
202
+ attrs: ["a", "b"].to_json,
203
+ params: {"a" => 3.3}.to_json,
204
+ }
205
+ res = ActiveSupport::JSON.decode(response.body).flatten.map{|x| x.round(8)}
206
+ expect(res).to eq([3.3, 9.9])
207
+ end
208
+
209
+ it "should be able to run scripts 2" do
210
+ get 'evaluate', {
211
+ format: :json,
212
+ script: "M3",
213
+ node: "C",
214
+ attrs: ["pc"].to_json,
215
+ }
216
+ # puts 'Z'*40, request.inspect
217
+ expect(response.body).to eq([7].to_json)
218
+
219
+ get 'evaluate', {
220
+ format: :json,
221
+ script: "M3",
222
+ node: "B",
223
+ attrs: ["pc"].to_json,
224
+ }
225
+ # puts 'Z'*40, request.inspect
226
+ expect(response.body).to eq([9].to_json)
227
+
228
+ get 'evaluate', {
229
+ format: :json,
230
+ script: "M3",
231
+ node: "A",
232
+ attrs: ["pc"].to_json,
233
+ }
234
+ # puts 'Z'*40, request.inspect
235
+ expect(response.body).to match(/"error":"undefined parameter p"/)
236
+ end
237
+
238
+ it "should be able to handle imports" do
239
+ get 'evaluate', {
240
+ format: :json,
241
+ script: "M4",
242
+ node: "A",
243
+ attrs: ["a", "c", "d", "pc"].to_json,
244
+ }
245
+ # puts 'Z'*40, request.inspect
246
+ expect(response.body).to eq([2,4,13,14].to_json)
247
+ end
248
+
249
+ it "should support CSV" do
250
+ get 'evaluate', {
251
+ format: :csv,
252
+ script: "M4",
253
+ node: "A",
254
+ attrs: ["a", "c", "d", "pc", "lc"].to_json,
255
+ }
256
+ # puts 'Z'*40, request.inspect
257
+ expect(response.body).to eq("2\r\n4\r\n13\r\n14\r\n14,14\r\n")
258
+ end
259
+
260
+ it "should support CSV (2)" do
261
+ get 'evaluate', {
262
+ format: :csv,
263
+ script: "M4",
264
+ node: "A",
265
+ attrs: ["result"].to_json,
266
+ }
267
+ # puts 'Z'*40, request.inspect
268
+ expect(response.body).to eq("a,b\r\n123,456\r\n789,101112\r\n")
269
+ end
270
+
271
+ it "should support api authorization - api_key not required" do
272
+ api = Marty::ApiAuth.new
273
+ api.app_name = 'TestApp'
274
+ api.script_name = 'M2'
275
+ api.save!
276
+
277
+ get 'evaluate', {
278
+ format: :json,
279
+ script: "M3",
280
+ node: "C",
281
+ attrs: ["pc"].to_json,
282
+ }
283
+ expect(response.body).to eq([7].to_json)
284
+ end
285
+
286
+ it "should support api authorization - api_key required but missing" do
287
+ api = Marty::ApiAuth.new
288
+ api.app_name = 'TestApp'
289
+ api.script_name = 'M3'
290
+ api.save!
291
+
292
+ get 'evaluate', {
293
+ format: :json,
294
+ script: "M3",
295
+ node: "C",
296
+ attrs: ["pc"].to_json,
297
+ }
298
+ expect(response.body).to match(/"error":"Permission denied"/)
299
+ end
300
+
301
+ it "should support api authorization - api_key required and supplied" do
302
+ api = Marty::ApiAuth.new
303
+ api.app_name = 'TestApp'
304
+ api.script_name = 'M3'
305
+ api.save!
306
+
307
+ get 'evaluate', {
308
+ format: :json,
309
+ script: "M3",
310
+ node: "C",
311
+ attrs: ["pc"].to_json,
312
+ api_key: api.api_key,
313
+ }
314
+ expect(response.body).to eq([7].to_json)
315
+ end
316
+
317
+ it "should support api authorization - api_key required but incorrect" do
318
+ api = Marty::ApiAuth.new
319
+ api.app_name = 'TestApp'
320
+ api.script_name = 'M3'
321
+ api.save!
322
+
323
+ get 'evaluate', {
324
+ format: :json,
325
+ script: "M3",
326
+ node: "C",
327
+ attrs: ["pc"].to_json,
328
+ api_key: api.api_key + 'x',
329
+ }
330
+ expect(response.body).to match(/"error":"Permission denied"/)
331
+ end
332
+
333
+ context "error handling" do
334
+ it 'returns bad attrs if attrs is not a string' do
335
+ get :evaluate, format: :json, attrs: 0
336
+ expect(response.body).to match(/"error":"Bad attrs"/)
337
+ end
338
+
339
+ it 'returns malformed attrs for improperly formatted json' do
340
+ get :evaluate, format: :json, attrs: "{"
341
+ expect(response.body).to match(/"error":"Malformed attrs"/)
342
+ end
343
+
344
+ it 'returns malformed attrs if attrs is not an array of strings' do
345
+ get :evaluate, format: :json, attrs: "{}"
346
+ expect(response.body).to match(/"error":"Malformed attrs"/)
347
+
348
+ get :evaluate, format: :json, attrs: "[0]"
349
+ expect(response.body).to match(/"error":"Malformed attrs"/)
350
+ end
351
+
352
+ it 'returns bad params if params is not a string' do
353
+ get(:evaluate, format: :json, params: 0)
354
+ expect(response.body).to match(/"error":"Bad params"/)
355
+ end
356
+
357
+ it 'returns malformed params for improperly formatted json' do
358
+ get :evaluate, format: :json, params: "{"
359
+ expect(response.body).to match(/"error":"Malformed params"/)
360
+ end
361
+
362
+ it 'returns malformed params if params is not a hash' do
363
+ get :evaluate, format: :json, params: "[0]"
364
+ expect(response.body).to match(/"error":"Malformed params"/)
365
+ end
366
+
367
+ it 'returns engine/tag lookup error if script not found' do
368
+ get :evaluate, format: :json, script: 'M1', tag: 'invalid'
369
+ expect(response.body).to match(/"error":"Can't get engine:/)
370
+ get :evaluate, format: :json, script: 'Invalid', tag: t1.name
371
+ expect(response.body).to match(/"error":"Can't get engine:/)
372
+ end
373
+
374
+ it 'returns the script runtime error (no node specified)' do
375
+ get :evaluate, format: :json, script: 'M1', tag: t1.name
376
+ expect(response.body).to match(/"error":"bad node/)
377
+ end
378
+ end
379
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Marty::RpcController do
4
+ before(:each) { @routes = Marty::Engine.routes }
5
+
6
+ before(:each) {
7
+ @tags = []
8
+ @tags << Marty::Script.load_script_bodies({
9
+ "A" => "A:\n a = 1\n",
10
+ "B" => "B:\n b = 0\n",
11
+ }, Date.today)
12
+
13
+ @tags << Marty::Script.load_script_bodies({
14
+ "B" => "import A\nB:\n b = A::A().a\n",
15
+ }, Date.today + 1.minute)
16
+
17
+ @tags << Marty::Script.load_script_bodies({
18
+ "A" => "A:\n a = 2\n",
19
+ }, Date.today + 2.minute)
20
+
21
+
22
+ # create an untagged version for DEV
23
+ s = Marty::Script.lookup('infinity', "A")
24
+ s.body = "A:\n a = 3\n"
25
+ s.save!
26
+ }
27
+
28
+ let(:tags) { @tags }
29
+
30
+ it "should properly import different versions of a script" do
31
+ # try the test 3 times for fun
32
+ (0..2).each {
33
+ tags.each_with_index { |t, i|
34
+ get 'evaluate', {
35
+ format: :json,
36
+ script: "B",
37
+ node: "B",
38
+ attrs: ["b"].to_json,
39
+ tag: t.name,
40
+ }
41
+ response.body.should == [i].to_json
42
+ }
43
+ }
44
+ end
45
+ end
@@ -0,0 +1,261 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb"
7
+ templates that are primarily responsible for inserting pre-built data in between
8
+ HTML tags. The model contains the "smart" domain objects (such as Account,
9
+ Product, Person, Post) that holds all the business logic and knows how to
10
+ persist themselves to a database. The controller handles the incoming requests
11
+ (such as Save New Account, Update Product, Show Post) by manipulating the model
12
+ and directing data to the view.
13
+
14
+ In Rails, the model is handled by what's called an object-relational mapping
15
+ layer entitled Active Record. This layer allows you to present the data from
16
+ database rows as objects and embellish these data objects with business logic
17
+ methods. You can read more about Active Record in
18
+ link:files/vendor/rails/activerecord/README.html.
19
+
20
+ The controller and view are handled by the Action Pack, which handles both
21
+ layers by its two parts: Action View and Action Controller. These two layers
22
+ are bundled in a single package due to their heavy interdependence. This is
23
+ unlike the relationship between the Active Record and Action Pack that is much
24
+ more separate. Each of these packages can be used independently outside of
25
+ Rails. You can read more about Action Pack in
26
+ link:files/vendor/rails/actionpack/README.html.
27
+
28
+
29
+ == Getting Started
30
+
31
+ 1. At the command prompt, create a new Rails application:
32
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
33
+
34
+ 2. Change directory to <tt>myapp</tt> and start the web server:
35
+ <tt>cd myapp; rails server</tt> (run with --help for options)
36
+
37
+ 3. Go to http://localhost:3000/ and you'll see:
38
+ "Welcome aboard: You're riding Ruby on Rails!"
39
+
40
+ 4. Follow the guidelines to start developing your application. You can find
41
+ the following resources handy:
42
+
43
+ * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44
+ * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45
+
46
+
47
+ == Debugging Rails
48
+
49
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
50
+ will help you debug it and get it back on the rails.
51
+
52
+ First area to check is the application log files. Have "tail -f" commands
53
+ running on the server.log and development.log. Rails will automatically display
54
+ debugging and runtime information to these files. Debugging info will also be
55
+ shown in the browser on requests from 127.0.0.1.
56
+
57
+ You can also log your own messages directly into the log file from your code
58
+ using the Ruby logger class from inside your controllers. Example:
59
+
60
+ class WeblogController < ActionController::Base
61
+ def destroy
62
+ @weblog = Weblog.find(params[:id])
63
+ @weblog.destroy
64
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65
+ end
66
+ end
67
+
68
+ The result will be a message in your log file along the lines of:
69
+
70
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71
+
72
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
73
+
74
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75
+ several books available online as well:
76
+
77
+ * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79
+
80
+ These two books will bring you up to speed on the Ruby language and also on
81
+ programming in general.
82
+
83
+
84
+ == Debugger
85
+
86
+ Debugger support is available through the debugger command when you start your
87
+ Mongrel or WEBrick server with --debugger. This means that you can break out of
88
+ execution at any point in the code, investigate and change the model, and then,
89
+ resume execution! You need to install ruby-debug to run the server in debugging
90
+ mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
91
+
92
+ class WeblogController < ActionController::Base
93
+ def index
94
+ @posts = Post.all
95
+ debugger
96
+ end
97
+ end
98
+
99
+ So the controller will accept the action, run the first line, then present you
100
+ with a IRB prompt in the server window. Here you can do things like:
101
+
102
+ >> @posts.inspect
103
+ => "[#<Post:0x14a6be8
104
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
105
+ #<Post:0x14a6620
106
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107
+ >> @posts.first.title = "hello from a debugger"
108
+ => "hello from a debugger"
109
+
110
+ ...and even better, you can examine how your runtime objects actually work:
111
+
112
+ >> f = @posts.first
113
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
114
+ >> f.
115
+ Display all 152 possibilities? (y or n)
116
+
117
+ Finally, when you're ready to resume execution, you can enter "cont".
118
+
119
+
120
+ == Console
121
+
122
+ The console is a Ruby shell, which allows you to interact with your
123
+ application's domain model. Here you'll have all parts of the application
124
+ configured, just like it is when the application is running. You can inspect
125
+ domain models, change values, and save to the database. Starting the script
126
+ without arguments will launch it in the development environment.
127
+
128
+ To start the console, run <tt>rails console</tt> from the application
129
+ directory.
130
+
131
+ Options:
132
+
133
+ * Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
134
+ made to the database.
135
+ * Passing an environment name as an argument will load the corresponding
136
+ environment. Example: <tt>rails console production</tt>.
137
+
138
+ To reload your controllers and models after launching the console run
139
+ <tt>reload!</tt>
140
+
141
+ More information about irb can be found at:
142
+ link:http://www.rubycentral.org/pickaxe/irb.html
143
+
144
+
145
+ == dbconsole
146
+
147
+ You can go to the command line of your database directly through <tt>rails
148
+ dbconsole</tt>. You would be connected to the database with the credentials
149
+ defined in database.yml. Starting the script without arguments will connect you
150
+ to the development database. Passing an argument will connect you to a different
151
+ database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
152
+ PostgreSQL and SQLite 3.
153
+
154
+ == Description of Contents
155
+
156
+ The default directory structure of a generated Ruby on Rails application:
157
+
158
+ |-- app
159
+ | |-- assets
160
+ | | |-- images
161
+ | | |-- javascripts
162
+ | | `-- stylesheets
163
+ | |-- controllers
164
+ | |-- helpers
165
+ | |-- mailers
166
+ | |-- models
167
+ | `-- views
168
+ | `-- layouts
169
+ |-- config
170
+ | |-- environments
171
+ | |-- initializers
172
+ | `-- locales
173
+ |-- db
174
+ |-- doc
175
+ |-- lib
176
+ | |-- assets
177
+ | `-- tasks
178
+ |-- log
179
+ |-- public
180
+ |-- script
181
+ |-- test
182
+ | |-- fixtures
183
+ | |-- functional
184
+ | |-- integration
185
+ | |-- performance
186
+ | `-- unit
187
+ |-- tmp
188
+ | `-- cache
189
+ | `-- assets
190
+ `-- vendor
191
+ |-- assets
192
+ | |-- javascripts
193
+ | `-- stylesheets
194
+ `-- plugins
195
+
196
+ app
197
+ Holds all the code that's specific to this particular application.
198
+
199
+ app/assets
200
+ Contains subdirectories for images, stylesheets, and JavaScript files.
201
+
202
+ app/controllers
203
+ Holds controllers that should be named like weblogs_controller.rb for
204
+ automated URL mapping. All controllers should descend from
205
+ ApplicationController which itself descends from ActionController::Base.
206
+
207
+ app/models
208
+ Holds models that should be named like post.rb. Models descend from
209
+ ActiveRecord::Base by default.
210
+
211
+ app/views
212
+ Holds the template files for the view that should be named like
213
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
214
+ eRuby syntax by default.
215
+
216
+ app/views/layouts
217
+ Holds the template files for layouts to be used with views. This models the
218
+ common header/footer method of wrapping views. In your views, define a layout
219
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
220
+ Inside default.html.erb, call <% yield %> to render the view using this
221
+ layout.
222
+
223
+ app/helpers
224
+ Holds view helpers that should be named like weblogs_helper.rb. These are
225
+ generated for you automatically when using generators for controllers.
226
+ Helpers can be used to wrap functionality for your views into methods.
227
+
228
+ config
229
+ Configuration files for the Rails environment, the routing map, the database,
230
+ and other dependencies.
231
+
232
+ db
233
+ Contains the database schema in schema.rb. db/migrate contains all the
234
+ sequence of Migrations for your schema.
235
+
236
+ doc
237
+ This directory is where your application documentation will be stored when
238
+ generated using <tt>rake doc:app</tt>
239
+
240
+ lib
241
+ Application specific libraries. Basically, any kind of custom code that
242
+ doesn't belong under controllers, models, or helpers. This directory is in
243
+ the load path.
244
+
245
+ public
246
+ The directory available for the web server. Also contains the dispatchers and the
247
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
248
+ server.
249
+
250
+ script
251
+ Helper scripts for automation and generation.
252
+
253
+ test
254
+ Unit and functional tests along with fixtures. When using the rails generate
255
+ command, template test files will be generated for you and placed in this
256
+ directory.
257
+
258
+ vendor
259
+ External libraries that the application depends on. Also includes the plugins
260
+ subdirectory. If the app has frozen rails, those gems also go here, under
261
+ vendor/rails/. This directory is in the load path.