magic_carpet 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +202 -0
- data/README.md +232 -0
- data/Rakefile +15 -0
- data/app/assets/javascripts/magic_carpet/application.js +13 -0
- data/app/assets/javascripts/magic_carpet/magic_carpet.js +80 -0
- data/app/assets/stylesheets/magic_carpet/application.css +13 -0
- data/app/controllers/magic_carpet/application_controller.rb +4 -0
- data/app/controllers/magic_carpet/js_fixtures_controller.rb +110 -0
- data/app/helpers/magic_carpet/application_helper.rb +4 -0
- data/app/helpers/magic_carpet/js_fixtures_helper.rb +139 -0
- data/config/routes.rb +3 -0
- data/lib/magic_carpet/engine.rb +12 -0
- data/lib/magic_carpet/version.rb +3 -0
- data/lib/magic_carpet.rb +4 -0
- data/lib/tasks/magic_carpet_tasks.rake +4 -0
- data/spec/controllers/magic_carpet/js_fixtures_controller_spec.rb +275 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/jquery-2.1.0.js +9111 -0
- data/spec/dummy/app/assets/javascripts/users.js +2 -0
- data/spec/dummy/app/assets/javascripts/wishes.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/spec/dummy/app/assets/stylesheets/users.css +4 -0
- data/spec/dummy/app/assets/stylesheets/wishes.css +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/users_controller.rb +58 -0
- data/spec/dummy/app/controllers/wishes_controller.rb +70 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/users_helper.rb +2 -0
- data/spec/dummy/app/helpers/wishes_helper.rb +2 -0
- data/spec/dummy/app/models/user.rb +3 -0
- data/spec/dummy/app/models/wish.rb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +19 -0
- data/spec/dummy/app/views/layouts/other_layout.html.erb +15 -0
- data/spec/dummy/app/views/shared/_id_able.html.erb +5 -0
- data/spec/dummy/app/views/users/_form.html.erb +29 -0
- data/spec/dummy/app/views/users/edit.html.erb +6 -0
- data/spec/dummy/app/views/users/index.html.erb +31 -0
- data/spec/dummy/app/views/users/new.html.erb +5 -0
- data/spec/dummy/app/views/users/show.html.erb +19 -0
- data/spec/dummy/app/views/wishes/_form.html.erb +21 -0
- data/spec/dummy/app/views/wishes/_some_partial.html.erb +1 -0
- data/spec/dummy/app/views/wishes/_wish.html.erb +6 -0
- data/spec/dummy/app/views/wishes/_wish_list_item.html.erb +3 -0
- data/spec/dummy/app/views/wishes/edit.html.erb +6 -0
- data/spec/dummy/app/views/wishes/index.html.erb +22 -0
- data/spec/dummy/app/views/wishes/local_models.html.erb +3 -0
- data/spec/dummy/app/views/wishes/locals.html.erb +6 -0
- data/spec/dummy/app/views/wishes/new.html.erb +5 -0
- data/spec/dummy/app/views/wishes/numbers.html.erb +4 -0
- data/spec/dummy/app/views/wishes/plain.html.erb +1 -0
- data/spec/dummy/app/views/wishes/show.html.erb +9 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +28 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +9 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20140201230228_create_wishes.rb +9 -0
- data/spec/dummy/db/migrate/20140201230247_create_users.rb +11 -0
- data/spec/dummy/db/migrate/20140208042514_associate_users_and_wishes.rb +5 -0
- data/spec/dummy/db/schema.rb +31 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +21112 -0
- data/spec/dummy/log/test.log +33634 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/javascripts/helpers/spec_helper.js +367 -0
- data/spec/dummy/spec/javascripts/magic_carpet_spec.js +314 -0
- data/spec/dummy/spec/javascripts/support/jasmine.yml +29 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0743af5c3f490550c6a448f45e6889b4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0800f54ee19cf3cee10b956fa9786799 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/082245bc7cce1345893a81643f76284a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/08b0d9573e11dc361c93563cec2a0106 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/09f277e17472af932cda6f7dd86ff943 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0e3142f2ae2a0b8902383f65b86a5299 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0f87038bb320b83592e071bff83e4195 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/10925724a66880466e7f3b4e158196cb +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/10fb651bf6e564ad505e391670c11a8d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/12090b2e7e2e9ac2632e486d02ee346a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/142047722c23a8e9a96c6355d224b67e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1b4c56479f40fe3f7fc8daf684f4f71c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1c3579416ea74586464f5969c6949d5d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1e259f0863fa6da47ded59eef77ac351 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/21d2c592e1570709ecd1208a030cfc66 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/220ab8240fd9e0712b64dd9ff515f5df +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/277a51802284d997817fcaca55211243 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/28c409c3bba590030a8074120aa781db +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/35906b4cd565b14db8ba786fc66c7eb3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/388a1d725ffd01cc06a34d720ea97775 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4050a4e5062ab95c9f32e9b6940821ea +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/442917e5b534e0e7ac0a3bac0c5299e7 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/45ccf991e042a7cf7abe52d1125eeae3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/469198efe71fedae413489ff2fad66e4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4817f65b5fc5c2042e04af7eb83a4c99 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/497ff8927ce695e3febb3cdfd3e4a74e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/510da110ae528e2d22533be39ff696c5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/51202fde1d49c04c5d5588ca203b7b1e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/55ea602f40a0ad2185e22964a16b4d42 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/596788b2d37e650dd4cf582b185f9d37 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5c09faba4e454de97f078861e82db15c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5f1a0d05e77ca8b9a1fc2a47e17a8174 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/64de9e1fa2dd01768d6e85552dcdb18a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/68c5fa1f98ca79274b1f6750d8611af5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6bcea01ea8389e9a2ee296904803a01c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7406b6e2ecfc7b024db7822fb753c796 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/744bda5bad4a3b9b9b244a4583fb6e29 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/786804147f5da16b37ef8932e422797c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/793dc2ede21315a9eabfe2b0a0ff13d4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7b1c8fbfabc405ee6e5c8887095e6b43 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7c2edc3a2733a7bc22c572af66983a2e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7cd1032c2c1fa8a02016ac207cd9c76f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7d4bf0f7a6d67ade27f05b9bbdfaa13f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/809136388a8f6d7a862b20361fad205c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/80ba335c5610df2a1defeab247d03cc9 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/817b43e6477d4059b9006261356b7147 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/81b537f4760199f4030b928268605909 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/83521bb0fd5da34426e16d8825eb314e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/85b590662faa5956a7cb3a38390f16ca +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8733ef9be8fb368ac9aa5b1ccbfce14c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/87b209c0c9da28094a8d5581a21262c6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8931ae3296ab13e8eed90f434208887f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8cb4c1afbd9a270155d8cdd697a8b20d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8d1f1fbd708160b30af96a108fef6c0d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/91ef1ca0ef363be62f4a38fb3fbc2291 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/9a25637a28779d7c49c40044188bd0e5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a0d10779d647db6ab1328734733a0e4d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a0e04aab47dc3631152c26632687f898 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a74883b193a8e72f27cba5703a696a89 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a839288628913e4533ef8cba740de1eb +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a95ead461bd72142ffb3040f8cd7cfa0 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ac47afc414ae67e366a330dc003edf1a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b1d1383958868d6f0e9e05c848682d70 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b4ff5ac95c02b56ca97786b337f8b845 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b718bc4e8c8146520d982e086897fe24 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b848029d2fa6db3db28ccbce818b399b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ba05f15307eb6d2c7e31e50768867139 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c1a8bdfcb2dca842a48acc85d3ff658a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c2eb6c5cabed0e6b333c035ac8400bbc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c3dbe303660d299b488648fc157fd32b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c45af704cb234484a8e1d0852f8fe0bc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c4868ba5188e0672b480e24d979224d0 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/caa2f86bb055636b69e292f2ae993914 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ce4b669883cb8df0ccd1c6aca12e0434 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cebc6db0bbb8120f430da3970b173d2f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d8a7bed1e7150777f59a9e107c1acaa8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/db4f843f0e597f7ba079bec345a91d58 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/dd5a838f402c1f78ff0f6e43b3ce6624 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/dfd7187ca1d53815395570d20d933e13 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e4092eb95487a855cb730373c97b8756 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e41b3d9532b5ef87c246ef6eb88417ed +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e8266bddb6510ce3a2bc5ae1469ab3f6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e86f67e739e4d85d5b8b1830b327ee67 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/efc1c13c84f6f8686ade375b47913c8d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f1e3cae1b4d4c1085b32f88d26fd1f89 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f21b1a83f2c41f61ba73c424b057ee19 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f25cc7f3223a9259336cb2dd38df220e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f56253b5f374fff1a33fbbc9881c9124 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/10fb651bf6e564ad505e391670c11a8d +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/142047722c23a8e9a96c6355d224b67e +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/4050a4e5062ab95c9f32e9b6940821ea +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/51202fde1d49c04c5d5588ca203b7b1e +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/596788b2d37e650dd4cf582b185f9d37 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/5f1a0d05e77ca8b9a1fc2a47e17a8174 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/81b537f4760199f4030b928268605909 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/87b209c0c9da28094a8d5581a21262c6 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/8cb4c1afbd9a270155d8cdd697a8b20d +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/f56253b5f374fff1a33fbbc9881c9124 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/jasmine/assets/application.js +9132 -0
- data/spec/dummy/tmp/jasmine/assets/boot.js +204 -0
- data/spec/dummy/tmp/jasmine/assets/helpers/spec_helper.js +462 -0
- data/spec/dummy/tmp/jasmine/assets/jasmine-console-reporter.js +125 -0
- data/spec/dummy/tmp/jasmine/assets/jasmine-console-shims.js +31 -0
- data/spec/dummy/tmp/jasmine/assets/jasmine-html.js +360 -0
- data/spec/dummy/tmp/jasmine/assets/jasmine-specs.js +0 -0
- data/spec/dummy/tmp/jasmine/assets/jasmine.css +55 -0
- data/spec/dummy/tmp/jasmine/assets/jasmine.js +2403 -0
- data/spec/dummy/tmp/jasmine/assets/jquery-2.1.0.js +9112 -0
- data/spec/dummy/tmp/jasmine/assets/json2.js +479 -0
- data/spec/dummy/tmp/jasmine/assets/magic_carpet/application.js +95 -0
- data/spec/dummy/tmp/jasmine/assets/magic_carpet/magic_carpet.js +81 -0
- data/spec/dummy/tmp/jasmine/assets/magic_carpet_spec.js +317 -0
- data/spec/dummy/tmp/jasmine/assets/users.js +3 -0
- data/spec/dummy/tmp/jasmine/assets/wishes.js +3 -0
- data/spec/dummy/tmp/jasmine/runner.html +28 -0
- data/spec/dummy/tmp/pids/server.pid +1 -0
- data/spec/helpers/magic_carpet/js_fixtures_helper_spec.rb +249 -0
- data/spec/spec_helper.rb +14 -0
- metadata +590 -0
@@ -0,0 +1,139 @@
|
|
1
|
+
module MagicCarpet
|
2
|
+
module JsFixturesHelper
|
3
|
+
attr_accessor :models
|
4
|
+
NIL = "nil"
|
5
|
+
|
6
|
+
def hydrate(value)
|
7
|
+
if array?(value)
|
8
|
+
hydrate_array(value)
|
9
|
+
elsif date?(value)
|
10
|
+
hydrate_date(value)
|
11
|
+
elsif time?(value)
|
12
|
+
hydrate_time(value)
|
13
|
+
elsif datetime?(value)
|
14
|
+
hydrate_datetime(value)
|
15
|
+
elsif model?(value)
|
16
|
+
hydrate_model(value)
|
17
|
+
elsif number?(value)
|
18
|
+
hydrate_number(value)
|
19
|
+
elsif array_as_hash?(value)
|
20
|
+
hydrate_array(value.values)
|
21
|
+
elsif hash?(value)
|
22
|
+
hydrate_hash(value)
|
23
|
+
elsif is_nil?(value)
|
24
|
+
nil
|
25
|
+
elsif true?(value)
|
26
|
+
true
|
27
|
+
elsif false?(value)
|
28
|
+
false
|
29
|
+
else
|
30
|
+
value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def hydrate_hash(hash)
|
37
|
+
hash.each do |key, value|
|
38
|
+
hash[key] = hydrate(value)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def hydrate_array(array)
|
43
|
+
array.map do |element|
|
44
|
+
hydrate(element)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def hydrate_number(hash)
|
49
|
+
number = hash[:number]
|
50
|
+
hash[:integer] ? number.to_i : number.to_f
|
51
|
+
end
|
52
|
+
|
53
|
+
def hydrate_date(hash)
|
54
|
+
Date.parse(hash[:date])
|
55
|
+
end
|
56
|
+
|
57
|
+
def hydrate_time(hash)
|
58
|
+
time = Time.parse(hash[:time])
|
59
|
+
time = time.utc if hash.key?(:utc)
|
60
|
+
time
|
61
|
+
end
|
62
|
+
|
63
|
+
def hydrate_datetime(hash)
|
64
|
+
DateTime.parse(hash[:datetime])
|
65
|
+
end
|
66
|
+
|
67
|
+
def hydrate_model(hash)
|
68
|
+
hydrate_hash(hash)
|
69
|
+
|
70
|
+
model_name = hash.delete(:model)
|
71
|
+
model = get_model(model_name)
|
72
|
+
model.new(hash)
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_model(model_name)
|
76
|
+
self.models ||= {}
|
77
|
+
self.models[model_name] ||= self.class.const_get(model_name)
|
78
|
+
end
|
79
|
+
|
80
|
+
def hash?(value)
|
81
|
+
value.is_a?(Hash)
|
82
|
+
end
|
83
|
+
|
84
|
+
def array?(value)
|
85
|
+
value.is_a?(Array)
|
86
|
+
end
|
87
|
+
|
88
|
+
def array_as_hash?(value)
|
89
|
+
if hash?(value) && value.present?
|
90
|
+
keys = value.keys.sort
|
91
|
+
keys.each_with_index.all? do |key, i|
|
92
|
+
key.to_s == i.to_s
|
93
|
+
end
|
94
|
+
else
|
95
|
+
false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def model?(value)
|
100
|
+
hash_with_key?(value, :model)
|
101
|
+
end
|
102
|
+
|
103
|
+
def number?(value)
|
104
|
+
hash_with_key?(value, :number)
|
105
|
+
end
|
106
|
+
|
107
|
+
def date?(value)
|
108
|
+
hash_with_key?(value, :date)
|
109
|
+
end
|
110
|
+
|
111
|
+
def time?(value)
|
112
|
+
hash_with_key?(value, :time)
|
113
|
+
end
|
114
|
+
|
115
|
+
def datetime?(value)
|
116
|
+
hash_with_key?(value, :datetime)
|
117
|
+
end
|
118
|
+
|
119
|
+
def hash_with_key?(value, key)
|
120
|
+
hash?(value) && value.key?(key)
|
121
|
+
end
|
122
|
+
|
123
|
+
def is_nil?(value)
|
124
|
+
same_string?(value, NIL)
|
125
|
+
end
|
126
|
+
|
127
|
+
def true?(value)
|
128
|
+
same_string?(value, true)
|
129
|
+
end
|
130
|
+
|
131
|
+
def false?(value)
|
132
|
+
same_string?(value, false)
|
133
|
+
end
|
134
|
+
|
135
|
+
def same_string?(value, string)
|
136
|
+
value.is_a?(String) && value == string.to_s
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module MagicCarpet
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace MagicCarpet
|
4
|
+
|
5
|
+
config.generators do |g|
|
6
|
+
g.test_framework :rspec, :fixture => false
|
7
|
+
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
8
|
+
g.assets false
|
9
|
+
g.helper false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/magic_carpet.rb
ADDED
@@ -0,0 +1,275 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module MagicCarpet
|
4
|
+
describe JsFixturesController do
|
5
|
+
|
6
|
+
let(:body) { response.body }
|
7
|
+
|
8
|
+
it "renders a template based on the template param" do
|
9
|
+
get :index, controller_name: "Wishes", template: "plain", use_route: :magic_carpet
|
10
|
+
expect(body).to match("<h1>Plain</h1>\n")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "renders based on controller and action names if there's no template param" do
|
14
|
+
get :index, controller_name: "Wishes", action_name: "plain", use_route: :magic_carpet
|
15
|
+
expect(body).to match("<h1>Plain</h1>\n")
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "fetching a view without variables" do
|
19
|
+
it "returns the view's markup" do
|
20
|
+
get :index, controller_name: "Wishes", action_name: "plain", use_route: :magic_carpet
|
21
|
+
expect(body).to match("<h1>Plain</h1>\n")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "rendering a partial" do
|
26
|
+
it "is done by passing the partial's path in the partial option" do
|
27
|
+
hash = {
|
28
|
+
wish: { model: "Wish" }
|
29
|
+
}
|
30
|
+
get :index, partial: "form", controller_name: "Wishes", use_route: :magic_carpet, instance_variables: hash
|
31
|
+
expect(body).to match("<form")
|
32
|
+
expect(body).to match("Create Wish")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "passes collection through when passed" do
|
36
|
+
collection = [
|
37
|
+
{ model: "Wish", text: "wish text 1", id: 1 },
|
38
|
+
{ model: "Wish", text: "wish text 2", id: 2 },
|
39
|
+
{ model: "Wish", text: "wish text 3", id: 3 }
|
40
|
+
]
|
41
|
+
get :index, partial: "wish", collection: collection, controller_name: "Wishes", use_route: :magic_carpet
|
42
|
+
expect(body).to match("wish text 1")
|
43
|
+
expect(body).to match("wish text 2")
|
44
|
+
expect(body).to match("wish text 3")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "accepts the 'as' option" do
|
48
|
+
collection = [
|
49
|
+
{ model: "OpenStruct", id: 1 },
|
50
|
+
{ model: "User", id: 2 },
|
51
|
+
{ model: "Wish", id: 3 }
|
52
|
+
]
|
53
|
+
get :index, partial: "shared/id_able", collection: collection, as: "id_able", controller_name: "Wishes", use_route: :magic_carpet
|
54
|
+
expect(body).to match(/id: 1\n\s+class: OpenStruct/)
|
55
|
+
expect(body).to match(/id: 2\n\s+class: User/)
|
56
|
+
expect(body).to match(/id: 3\n\s+class: Wish/)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "fetching a view with local variables" do
|
61
|
+
it "interpretes the objects accurately" do
|
62
|
+
locals = {
|
63
|
+
some_hash: { key: "value" },
|
64
|
+
some_array: ["element"],
|
65
|
+
some_string: "hello",
|
66
|
+
some_model: { model: "Wish", text: "wish text" }
|
67
|
+
}
|
68
|
+
get :index, locals: locals, controller_name: "Wishes", action_name: "locals", use_route: :magic_carpet
|
69
|
+
expect(body).to match("some hash: value")
|
70
|
+
expect(body).to match(/some array: \[\"element\"\]/)
|
71
|
+
expect(body).to match("some string: hello")
|
72
|
+
expect(body).to match("some model: wish text")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "fetching a view with instance variables" do
|
77
|
+
it "sets the specified instance variables" do
|
78
|
+
instance_variables = {
|
79
|
+
wishes: [
|
80
|
+
{ id: "1", model: "Wish", text: "first wish" },
|
81
|
+
{ id: "2", model: "Wish", text: "second wish" },
|
82
|
+
{ id: "3", model: "Wish", text: "third wish" }
|
83
|
+
]
|
84
|
+
}
|
85
|
+
get :index, instance_variables: instance_variables, controller_name: "Wishes", action_name: "index", use_route: :magic_carpet
|
86
|
+
|
87
|
+
expect(body).to match("first wish")
|
88
|
+
expect(body).to match("second wish")
|
89
|
+
expect(body).to match("third wish")
|
90
|
+
expect(body).to match("/wishes/1")
|
91
|
+
expect(body).to match("/wishes/2")
|
92
|
+
expect(body).to match("/wishes/3")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "fetching a view with a specified layout" do
|
97
|
+
it "returns the view's markup without the layout" do
|
98
|
+
get :index, controller_name: "Wishes", action_name: "plain", use_route: :magic_carpet
|
99
|
+
expect(body).to eq("<h1>Plain</h1>\n")
|
100
|
+
expect(body).to_not match("<!DOCTYPE html>")
|
101
|
+
end
|
102
|
+
|
103
|
+
it "returns the view's markup with the specified layout" do
|
104
|
+
get :index, layout: "other_layout", controller_name: "Wishes", action_name: "plain", use_route: :magic_carpet
|
105
|
+
expect(body).to match("<h1>Other Layout</h1>")
|
106
|
+
expect(body).to_not match("<h1>Application Layout</h1>")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it "sets flash messages according to flash parameter" do
|
111
|
+
flash = {
|
112
|
+
warning: "this is a flash message",
|
113
|
+
notice: "something noteworthy"
|
114
|
+
}
|
115
|
+
get :index, flash: flash, layout: true, controller_name: "Wishes", action_name: "plain", use_route: :magic_carpet
|
116
|
+
controller_flash = controller.send(:controller).flash
|
117
|
+
expect(controller_flash["warning"]).to eq(flash[:warning])
|
118
|
+
expect(controller_flash["notice"]).to eq(flash[:notice])
|
119
|
+
end
|
120
|
+
|
121
|
+
it "sets the session according to session parameter" do
|
122
|
+
session_hash = { user_id: "4", wish_id: "9" }
|
123
|
+
get :index, session: session_hash, layout: true, controller_name: "Wishes", action_name: "plain", use_route: :magic_carpet
|
124
|
+
controller_session = controller.send(:controller).session
|
125
|
+
expect(controller_session["user_id"]).to eq("4")
|
126
|
+
expect(controller_session["wish_id"]).to eq("9")
|
127
|
+
end
|
128
|
+
|
129
|
+
it "sets the cookies according to the cookies parameter" do
|
130
|
+
cookies_hash = { user_id: "4", wish_id: "9" }
|
131
|
+
get :index, cookies: cookies_hash, layout: true, controller_name: "Wishes", action_name: "plain", use_route: :magic_carpet
|
132
|
+
controller_cookies = controller.send(:controller).send(:cookies)
|
133
|
+
expect(controller_cookies["user_id"]).to eq("4")
|
134
|
+
expect(controller_cookies["wish_id"]).to eq("9")
|
135
|
+
end
|
136
|
+
|
137
|
+
it "sets the params according to params parameter" do
|
138
|
+
params_hash = { user_id: "4", wish_id: "9" }
|
139
|
+
get :index, params: params_hash, layout: true, controller_name: "Wishes", action_name: "plain", use_route: :magic_carpet
|
140
|
+
controller_params = controller.send(:controller).params
|
141
|
+
expect(controller_params[:user_id]).to eq("4")
|
142
|
+
expect(controller_params[:wish_id]).to eq("9")
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "error handling" do
|
146
|
+
|
147
|
+
context "logging" do
|
148
|
+
it "logs NameErrors" do
|
149
|
+
expect(controller.logger).to receive(:error) do |message|
|
150
|
+
expect(message).to match("NonExistantController not found.")
|
151
|
+
expect(message).to match(/\n\s\s\s\s.*js_fixtures_controller.rb:\d\d:in \`const_get'\n/)
|
152
|
+
end
|
153
|
+
get :index, controller_name: "NonExistant", action_name: "plain", use_route: :magic_carpet
|
154
|
+
end
|
155
|
+
|
156
|
+
it "logs Time parse errors" do
|
157
|
+
expect(controller.logger).to receive(:error) do |message|
|
158
|
+
expect(message).to match("no time information in \"invalid-time\"\n")
|
159
|
+
expect(message).to match(/\n\s\s\s\s.*magic_carpet\//)
|
160
|
+
end
|
161
|
+
instance_variables_hash = {
|
162
|
+
wishes: [
|
163
|
+
{ id: 1, model: "Wish", created_at: { time: "invalid-time" } },
|
164
|
+
{ id: 1, model: "Wish", created_at: { time: Time.now.to_s } }
|
165
|
+
]
|
166
|
+
}
|
167
|
+
get :index, controller_name: "Wishes", action_name: "index", instance_variables: instance_variables_hash, use_route: :magic_carpet
|
168
|
+
end
|
169
|
+
|
170
|
+
it "logs Date/DateTime parse errors" do
|
171
|
+
expect(controller.logger).to receive(:error) do |message|
|
172
|
+
expect(message).to match("invalid date\n")
|
173
|
+
expect(message).to match(/\n\s\s\s\s.*magic_carpet\//)
|
174
|
+
end
|
175
|
+
instance_variables_hash = {
|
176
|
+
wishes: [
|
177
|
+
{ id: 1, model: "Wish", created_at: { date: "invalid-date" } },
|
178
|
+
{ id: 1, model: "Wish", created_at: { date: Date.today.to_s } }
|
179
|
+
]
|
180
|
+
}
|
181
|
+
get :index, controller_name: "Wishes", action_name: "index", instance_variables: instance_variables_hash, use_route: :magic_carpet
|
182
|
+
end
|
183
|
+
|
184
|
+
it "logs NoMethodErrors" do
|
185
|
+
expect(controller.logger).to receive(:error) do |message|
|
186
|
+
expect(message).to match("NoMethodError: undefined method `text' for #<User:")
|
187
|
+
expect(message).to match(/\n\s\s\s\s.*app\/views\/.*\.html\.erb:2/)
|
188
|
+
end
|
189
|
+
locals = { wish: { model: "User" } }
|
190
|
+
get :index, locals: locals, controller_name: "Wishes", partial: "wish", use_route: :magic_carpet
|
191
|
+
end
|
192
|
+
|
193
|
+
it "logs missing template errors" do
|
194
|
+
expect(controller.logger).to receive(:error) do |message|
|
195
|
+
expect(message).to match("Missing template wishes/fake, application/fake")
|
196
|
+
expect(message).to match(/\n\s\s\s\s.*gems\/actionpack/)
|
197
|
+
end
|
198
|
+
get :index, controller_name: "Wishes", template: "fake", use_route: :magic_carpet
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
context "json" do
|
203
|
+
it "reports missing/misnamed controllers" do
|
204
|
+
get :index, controller_name: "NonExistant", action_name: "plain", use_route: :magic_carpet
|
205
|
+
expected = { error: "Magic Carpet Error: NonExistantController not found." }.to_json
|
206
|
+
expect(body).to eq(expected)
|
207
|
+
expect(response.code).to eq("400")
|
208
|
+
end
|
209
|
+
|
210
|
+
it "reports Time parse errors" do
|
211
|
+
instance_variables_hash = {
|
212
|
+
wishes: [
|
213
|
+
{ id: 1, model: "Wish", created_at: { time: "invalid-time" } },
|
214
|
+
{ id: 1, model: "Wish", created_at: { time: Time.now.to_s } }
|
215
|
+
]
|
216
|
+
}
|
217
|
+
get :index, controller_name: "Wishes", action_name: "index", instance_variables: instance_variables_hash, use_route: :magic_carpet
|
218
|
+
expected = { error: "Magic Carpet Error: no time information in \"invalid-time\"" }.to_json
|
219
|
+
expect(body).to eq(expected)
|
220
|
+
expect(response.code).to eq("400")
|
221
|
+
end
|
222
|
+
|
223
|
+
it "reports Date/DateTime parse errors" do
|
224
|
+
instance_variables_hash = {
|
225
|
+
wishes: [
|
226
|
+
{ id: 1, model: "Wish", created_at: { date: "invalid-date" } },
|
227
|
+
{ id: 1, model: "Wish", created_at: { date: Date.today.to_s } }
|
228
|
+
]
|
229
|
+
}
|
230
|
+
get :index, controller_name: "Wishes", action_name: "index", instance_variables: instance_variables_hash, use_route: :magic_carpet
|
231
|
+
expected = { error: "Magic Carpet Error: invalid date" }.to_json
|
232
|
+
expect(body).to eq(expected)
|
233
|
+
expect(response.code).to eq("400")
|
234
|
+
end
|
235
|
+
|
236
|
+
it "reports missing/misnamed models" do
|
237
|
+
locals = { wish: { model: "Dish", text: "wish text" } }
|
238
|
+
get :index, locals: locals, controller_name: "Wishes", action_name: "plain", use_route: :magic_carpet
|
239
|
+
expected = { error: "Magic Carpet Error: Dish not found." }.to_json
|
240
|
+
expect(body).to eq(expected)
|
241
|
+
expect(response.code).to eq("400")
|
242
|
+
end
|
243
|
+
|
244
|
+
it "reports missing template errors" do
|
245
|
+
get :index, controller_name: "Wishes", template: "fake", use_route: :magic_carpet
|
246
|
+
expect(JSON.parse(body)["error"]).to match("Magic Carpet Error: Missing template wishes/fake, application/fake")
|
247
|
+
expect(response.code).to eq("400")
|
248
|
+
end
|
249
|
+
|
250
|
+
it "reports missing local variable errors" do
|
251
|
+
get :index, controller_name: "Wishes", template: "locals", use_route: :magic_carpet
|
252
|
+
expected = { error: "Magic Carpet Error: undefined local variable or method `some_hash' for 'locals' template." }.to_json
|
253
|
+
expect(body).to eq(expected)
|
254
|
+
expect(response.code).to eq("400")
|
255
|
+
end
|
256
|
+
|
257
|
+
it "reports missing partial errors" do
|
258
|
+
get :index, controller_name: "Wishes", partial: "zuh", use_route: :magic_carpet
|
259
|
+
expect(JSON.parse(body)["error"]).to match("Magic Carpet Error: Missing partial wishes/zuh, application/zuh")
|
260
|
+
expect(response.code).to eq("400")
|
261
|
+
end
|
262
|
+
|
263
|
+
it "reports no method errors" do
|
264
|
+
locals = { wish: { model: "User" } }
|
265
|
+
get :index, locals: locals, controller_name: "Wishes", partial: "wish", use_route: :magic_carpet
|
266
|
+
error = JSON.parse(body)["error"]
|
267
|
+
expect(error).to match("NoMethodError: undefined method `text' for #<User:")
|
268
|
+
expect(error).to match(/app\/views\/.*\.html\.erb:2/)
|
269
|
+
expect(error).to_not match("activesupport")
|
270
|
+
expect(response.code).to eq("400")
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|