magic_lamp 0.9.0

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 (69) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +202 -0
  3. data/README.md +104 -0
  4. data/lib/magic_lamp.rb +50 -0
  5. data/lib/magic_lamp/fixture_creator.rb +53 -0
  6. data/lib/magic_lamp/version.rb +3 -0
  7. data/lib/tasks/magic_lamp_tasks.rb +44 -0
  8. data/spec/dummy/README.rdoc +28 -0
  9. data/spec/dummy/Rakefile +6 -0
  10. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  11. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  12. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  13. data/spec/dummy/app/controllers/orders_controller.rb +58 -0
  14. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  15. data/spec/dummy/app/helpers/orders_helper.rb +2 -0
  16. data/spec/dummy/app/models/order.rb +2 -0
  17. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  18. data/spec/dummy/app/views/orders/_form.html.erb +17 -0
  19. data/spec/dummy/app/views/orders/edit.html.erb +6 -0
  20. data/spec/dummy/app/views/orders/foo.html.erb +1 -0
  21. data/spec/dummy/app/views/orders/index.html.erb +23 -0
  22. data/spec/dummy/app/views/orders/new.html.erb +5 -0
  23. data/spec/dummy/app/views/orders/show.html.erb +4 -0
  24. data/spec/dummy/bin/bundle +3 -0
  25. data/spec/dummy/bin/rails +4 -0
  26. data/spec/dummy/bin/rake +4 -0
  27. data/spec/dummy/config.ru +4 -0
  28. data/spec/dummy/config/application.rb +23 -0
  29. data/spec/dummy/config/boot.rb +5 -0
  30. data/spec/dummy/config/database.yml +25 -0
  31. data/spec/dummy/config/environment.rb +5 -0
  32. data/spec/dummy/config/environments/development.rb +37 -0
  33. data/spec/dummy/config/environments/production.rb +83 -0
  34. data/spec/dummy/config/environments/test.rb +39 -0
  35. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  36. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  37. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  38. data/spec/dummy/config/initializers/inflections.rb +16 -0
  39. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  40. data/spec/dummy/config/initializers/session_store.rb +3 -0
  41. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  42. data/spec/dummy/config/locales/en.yml +23 -0
  43. data/spec/dummy/config/routes.rb +58 -0
  44. data/spec/dummy/config/secrets.yml +22 -0
  45. data/spec/dummy/db/migrate/20140623002513_create_orders.rb +8 -0
  46. data/spec/dummy/db/schema.rb +21 -0
  47. data/spec/dummy/db/test.sqlite3 +0 -0
  48. data/spec/dummy/log/development.log +1 -0
  49. data/spec/dummy/log/test.log +17988 -0
  50. data/spec/dummy/public/404.html +67 -0
  51. data/spec/dummy/public/422.html +67 -0
  52. data/spec/dummy/public/500.html +66 -0
  53. data/spec/dummy/public/favicon.ico +0 -0
  54. data/spec/dummy/spec/magic_lamp.rb +4 -0
  55. data/spec/dummy/spec/magic_lamp/foo/foo_lamp.rb +1 -0
  56. data/spec/dummy/spec/magic_lamp/rake/rake_lamp.rb +3 -0
  57. data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  58. data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  59. data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  60. data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  61. data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  62. data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  63. data/spec/integration/integration_spec.rb +21 -0
  64. data/spec/lib/fixture_creator_spec.rb +142 -0
  65. data/spec/lib/magic_lamp_spec.rb +98 -0
  66. data/spec/rails_helper.rb +53 -0
  67. data/spec/spec_helper.rb +78 -0
  68. data/spec/tasks/magic_lamp_tasks_spec.rb +34 -0
  69. metadata +257 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,4 @@
1
+ MagicLamp.create_fixture("via_magic_lamp_file", OrdersController) do
2
+ @order = Order.new
3
+ render :new
4
+ end
@@ -0,0 +1 @@
1
+ MagicLamp.instance_variable_set("@foo", "from lamp file")
@@ -0,0 +1,3 @@
1
+ MagicLamp.create_fixture("rake_test", OrdersController) do
2
+ render :foo
3
+ end
@@ -0,0 +1,21 @@
1
+ require "rails_helper"
2
+
3
+ describe "Integration", integration: true do
4
+ let(:rake_test_path) { Rails.root.join("tmp/magic_lamp/rake_test.html") }
5
+ let(:magic_lamp_test_path) { Rails.root.join("tmp/magic_lamp/via_magic_lamp_file.html") }
6
+
7
+ it "creates fixture files from lamp files" do
8
+ Dir.chdir(Rails.root) do
9
+ system "rake db:drop"
10
+ system "rake db:create"
11
+ system "rake db:migrate"
12
+ system "rake magic_lamp"
13
+ end
14
+
15
+ expect(File.exist?(rake_test_path)).to eq(true)
16
+ expect(File.read(rake_test_path)).to eq("foo\n")
17
+
18
+ expect(File.exist?(magic_lamp_test_path)).to eq(true)
19
+ expect(File.read(magic_lamp_test_path)).to match("<h1>New order</h1>")
20
+ end
21
+ end
@@ -0,0 +1,142 @@
1
+ require "rails_helper"
2
+
3
+ describe MagicLamp::FixtureCreator do
4
+ before do
5
+ FileUtils.rm_rf(Rails.root.join("tmp/magic_lamp"))
6
+ end
7
+
8
+ context "attr_accessor" do
9
+ context "render_arguments" do
10
+ it { should respond_to :render_arguments }
11
+ it { should respond_to :render_arguments= }
12
+ end
13
+
14
+ context "namespace" do
15
+ it { should respond_to :namespace }
16
+ it { should respond_to :namespace= }
17
+ end
18
+ end
19
+
20
+ describe "#initialize" do
21
+ it "sets MagicLamp as namespace" do
22
+ expect(subject.namespace).to eq(MagicLamp)
23
+ end
24
+ end
25
+
26
+ describe "#create_fixture" do
27
+ let(:fixture_path) { Rails.root.join("tmp/magic_lamp/fixture_name.html") }
28
+
29
+ before do
30
+ MagicLamp.create_tmp_directory
31
+ subject.create_fixture("fixture_name", OrdersController) do
32
+ render :foo
33
+ end
34
+ end
35
+
36
+ it "gives the fixture file specified name in the tmp path" do
37
+ expect(File.exist?(fixture_path)).to eq(true)
38
+ end
39
+
40
+ it "contains the template" do
41
+ expect(File.read(fixture_path)).to eq("foo\n")
42
+ end
43
+
44
+ it "does not render the layout by default" do
45
+ expect(File.read(fixture_path)).to_not match(/The layout/)
46
+ end
47
+ end
48
+
49
+ describe "#new_controller" do
50
+
51
+ it "returns an instance of the passed controller class" do
52
+ expect(subject.new_controller(OrdersController) {} ).to be_a(OrdersController)
53
+ end
54
+
55
+ context "contoller" do
56
+ let(:controller) { subject.new_controller(OrdersController) { params[:foo] = "bar" } }
57
+
58
+ it "can have render_to_string called on it without blowing up" do
59
+ expect do
60
+ controller.render_to_string :foo
61
+ end.to_not raise_error
62
+ end
63
+
64
+ it "has had its state set by the given block" do
65
+ expect(controller.params[:foo]).to eq("bar")
66
+ end
67
+
68
+ context "stubbed controller#render" do
69
+ it "passes its arguments to the fixture creator at render arguments" do
70
+ controller.render :foo, :bar
71
+ expect(subject.render_arguments).to eq([:foo, :bar])
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "#munge_arguments" do
78
+ context "no options" do
79
+ let(:munged_arguments) { subject.munge_arguments([:foo]) }
80
+ let(:options) { munged_arguments.last }
81
+
82
+ it "provides a hash as the final argument if there isn't one already" do
83
+ expect(options).to be_a(Hash)
84
+ end
85
+
86
+ it "sets layout to false" do
87
+ expect(options[:layout]).to eq(false)
88
+ end
89
+
90
+ it "preserves the first argument" do
91
+ expect(munged_arguments.size).to eq(2)
92
+ expect(munged_arguments.first).to eq(:foo)
93
+ end
94
+ end
95
+
96
+ context "with options" do
97
+ let(:munged_arguments) { subject.munge_arguments([:foo, some_option: true]) }
98
+ let(:options) { munged_arguments.last }
99
+
100
+ it "preserves the other options" do
101
+ expect(options[:some_option]).to eq(true)
102
+ end
103
+
104
+ it "sets layout to false" do
105
+ expect(options[:layout]).to eq(false)
106
+ end
107
+
108
+ it "preserves the first argument" do
109
+ expect(munged_arguments.first).to eq(:foo)
110
+ end
111
+
112
+ context "layout specified" do
113
+ let(:munged_arguments) { subject.munge_arguments([:foo, layout: "bar"]) }
114
+
115
+ it "preserves the layout value" do
116
+ expect(options[:layout]).to eq("bar")
117
+ end
118
+ end
119
+ end
120
+
121
+ context "only options" do
122
+ let(:munged_arguments) { subject.munge_arguments([partial: "foo"]) }
123
+ let(:options) { munged_arguments.first }
124
+
125
+ it "preserves the other options" do
126
+ expect(options[:partial]).to eq("foo")
127
+ end
128
+
129
+ it "sets layout to false" do
130
+ expect(options[:layout]).to eq(false)
131
+ end
132
+
133
+ context "layout specified" do
134
+ let(:munged_arguments) { subject.munge_arguments([partial: "foo", layout: "bar"]) }
135
+
136
+ it "preserves the layout value" do
137
+ expect(options[:layout]).to eq("bar")
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,98 @@
1
+ require "rails_helper"
2
+
3
+ describe MagicLamp do
4
+
5
+ describe "#path" do
6
+ context "spec directory" do
7
+ let(:spec_path) { Rails.root.join("spec") }
8
+
9
+ it "returns a default path starting from spec" do
10
+ expect(subject.path).to eq(spec_path)
11
+ end
12
+ end
13
+
14
+ context "no spec directory" do
15
+ let(:test_path) { Rails.root.join("test") }
16
+
17
+ it "returns a default path starting from test" do
18
+ allow(Dir).to receive(:exist?).and_return(false)
19
+ expect(subject.path).to eq(test_path)
20
+ end
21
+ end
22
+ end
23
+
24
+ describe "#tmp_path" do
25
+ let(:tmp_path) { Rails.root.join("tmp/magic_lamp") }
26
+
27
+ it "returns the path to tmp" do
28
+ expect(subject.tmp_path).to eq(tmp_path)
29
+ end
30
+ end
31
+
32
+ describe "#create_tmp_directory" do
33
+ let(:tmp_directory) { subject.tmp_path }
34
+
35
+ before do
36
+ subject.create_tmp_directory
37
+ end
38
+
39
+ it "creates the magic lamp tmp directory" do
40
+ expect(File.exist?(tmp_directory)).to eq(true)
41
+ end
42
+
43
+ it "doesn't throw an error when the directory already exists" do
44
+ expect do
45
+ subject.create_tmp_directory
46
+ end.to_not raise_error
47
+ end
48
+ end
49
+
50
+ describe "#remove_tmp_directory" do
51
+ let(:tmp_directory) { subject.tmp_path }
52
+
53
+ before do
54
+ subject.create_tmp_directory
55
+ subject.remove_tmp_directory
56
+ end
57
+
58
+ it "removes the magic lamp tmp directory" do
59
+ expect(File.exist?(tmp_directory)).to eq(false)
60
+ end
61
+
62
+ it "doesn't throw an error when the directory doesn't exist before deletion" do
63
+ expect do
64
+ subject.remove_tmp_directory
65
+ end.to_not raise_error
66
+ end
67
+ end
68
+
69
+ describe "#create_fixture" do
70
+
71
+ it "passes through its arguments and block to an instance of FixtureCreator" do
72
+ passed_block = Proc.new { render :foo }
73
+ fixture_creator = MagicLamp::FixtureCreator.new
74
+ allow(MagicLamp::FixtureCreator).to receive(:new).and_return(fixture_creator)
75
+
76
+ expect(fixture_creator).to receive(:create_fixture) do |fixture_name, controller_class, &block|
77
+ expect(fixture_name).to eq("foo")
78
+ expect(controller_class).to eq(OrdersController)
79
+ expect(block).to eq(passed_block)
80
+ end
81
+
82
+ subject.create_fixture("foo", OrdersController, &passed_block)
83
+ end
84
+ end
85
+
86
+ describe "#load_lamp_files" do
87
+
88
+ it "calls create_tmp_directory" do
89
+ expect(subject).to receive(:create_tmp_directory).and_call_original
90
+ subject.load_lamp_files
91
+ end
92
+
93
+ it "loads all _lamp files in the specified path" do
94
+ subject.load_lamp_files
95
+ expect(subject.instance_eval("@foo")).to eq("from lamp file")
96
+ end
97
+ end
98
+ end