mack 0.5.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/CHANGELOG +34 -0
  2. data/README +1 -1
  3. data/bin/mack +7 -2
  4. data/lib/controller/controller.rb +371 -0
  5. data/lib/controller/cookie_jar.rb +2 -1
  6. data/lib/controller/filter.rb +3 -2
  7. data/lib/controller/request.rb +30 -26
  8. data/lib/controller/session.rb +5 -0
  9. data/lib/distributed/utils/rinda.rb +1 -1
  10. data/lib/errors/errors.rb +5 -3
  11. data/lib/generators/mack_application_generator/mack_application_generator.rb +4 -0
  12. data/lib/generators/mack_application_generator/manifest.yml +40 -7
  13. data/lib/generators/mack_application_generator/templates/Rakefile.template +5 -1
  14. data/lib/generators/mack_application_generator/templates/app/controllers/default_controller.rb.template +2 -1
  15. data/lib/generators/mack_application_generator/templates/app/helpers/controllers/default_controller_helper.rb.template +7 -0
  16. data/lib/generators/mack_application_generator/templates/app/helpers/views/application_helper.rb.template +7 -0
  17. data/lib/generators/mack_application_generator/templates/config/app_config/default.yml.template +2 -1
  18. data/lib/generators/mack_application_generator/templates/config/database.yml.template +11 -10
  19. data/lib/generators/mack_application_generator/templates/test/functional/default_controller_spec.rb.template +9 -0
  20. data/lib/generators/mack_application_generator/templates/test/functional/default_controller_test.rb.template +10 -0
  21. data/lib/generators/mack_application_generator/templates/test/spec.opts.template +2 -0
  22. data/lib/generators/mack_application_generator/templates/test/spec_helper.rb.template +8 -0
  23. data/lib/generators/mack_application_generator/templates/test/test_helper.rb.template +2 -1
  24. data/lib/initialization/application.rb +46 -0
  25. data/lib/initialization/configuration.rb +23 -38
  26. data/lib/initialization/console.rb +5 -2
  27. data/lib/initialization/helpers.rb +31 -0
  28. data/lib/initialization/logging.rb +69 -15
  29. data/lib/initialization/orm_support.rb +10 -4
  30. data/lib/initialization/plugins.rb +1 -1
  31. data/lib/mack.rb +18 -76
  32. data/lib/mack_tasks.rb +4 -1
  33. data/lib/rendering/engine/erubis.rb +1 -1
  34. data/lib/rendering/engine/registry.rb +5 -5
  35. data/lib/rendering/type/action.rb +3 -2
  36. data/lib/rendering/type/base.rb +1 -1
  37. data/lib/rendering/type/layout.rb +2 -2
  38. data/lib/rendering/type/partial.rb +1 -1
  39. data/lib/rendering/type/public.rb +1 -1
  40. data/lib/rendering/type/template.rb +1 -1
  41. data/lib/rendering/type/url.rb +4 -4
  42. data/lib/rendering/type/xml.rb +3 -2
  43. data/lib/rendering/view_template.rb +7 -7
  44. data/lib/routing/route_map.rb +27 -5
  45. data/lib/routing/urls.rb +1 -0
  46. data/lib/runner.rb +52 -17
  47. data/lib/tasks/cachetastic_tasks.rake +2 -2
  48. data/lib/tasks/mack_server_tasks.rake +2 -4
  49. data/lib/tasks/mack_update_tasks.rake +26 -0
  50. data/lib/tasks/rake_rules.rake +6 -2
  51. data/lib/tasks/test_tasks.rake +28 -10
  52. data/lib/testing/helpers.rb +187 -0
  53. data/lib/testing/response.rb +49 -0
  54. data/lib/testing/rspec.rb +20 -0
  55. data/lib/testing/test_assertions.rb +55 -0
  56. data/lib/{test_extensions → testing}/test_case.rb +9 -7
  57. data/lib/utils/crypt/keeper.rb +1 -1
  58. data/lib/utils/server.rb +2 -2
  59. data/lib/view_helpers/html_helpers.rb +4 -0
  60. metadata +26 -40
  61. data/lib/controller/base.rb +0 -345
  62. data/lib/generators/mack_application_generator/templates/app/helpers/application_helper.rb.template +0 -2
  63. data/lib/generators/mack_application_generator/templates/config/thin.ru.template +0 -1
  64. data/lib/generators/mack_application_generator/templates/config/thin.yml.template +0 -8
  65. data/lib/rendering/engine/haml.rb +0 -18
  66. data/lib/rendering/engine/markaby.rb +0 -28
  67. data/lib/test_extensions/test_assertions.rb +0 -55
  68. data/lib/test_extensions/test_helpers.rb +0 -192
@@ -1 +0,0 @@
1
- run Mack::Utils::Server.build_app
@@ -1,8 +0,0 @@
1
- ---
2
- pid: tmp/pids/thin.pid
3
- log: log/thin.log
4
- timeout: 60
5
- port: 3000
6
- rackup: config/thin.ru
7
- address: 0.0.0.0
8
- # servers: 10
@@ -1,18 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'base')
2
- module Mack
3
- module Rendering
4
- module Engine
5
- class Haml < Mack::Rendering::Engine::Base
6
-
7
- def render(io, binding)
8
- ::Haml::Engine.new(io).render(binding)
9
- end
10
-
11
- def extension
12
- :haml
13
- end
14
-
15
- end
16
- end
17
- end
18
- end
@@ -1,28 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "view_template")
2
- require File.join(File.dirname(__FILE__), 'base')
3
- module Mack
4
- module Rendering
5
- module Engine
6
- class Markaby < Mack::Rendering::Engine::Base
7
-
8
- def render(io, binding)
9
- @_markaby = ::Markaby::Builder.new({}, self.view_template)
10
- self.view_template.instance_variable_set("@_markaby", @_markaby)
11
- eval(io, binding)
12
- end
13
-
14
- def extension
15
- :mab
16
- end
17
-
18
- module ViewHelpers
19
- def mab
20
- @_markaby
21
- end
22
- end
23
-
24
- end
25
- end
26
- end
27
- end
28
- Mack::Rendering::ViewTemplate.send(:include, Mack::Rendering::Engine::Markaby::ViewHelpers)
@@ -1,55 +0,0 @@
1
- require 'test/unit'
2
- module Mack
3
-
4
- module TestAssertions
5
-
6
- # Takes either a Symbol or a Fixnum and assert the response matches it.
7
- # The symbols it will match are :success, :redirect, :not_found, :error.
8
- # If a Fixnum is passed it will assert the response status equals that Fixnum
9
- def assert_response(status)
10
- if status.is_a?(Symbol)
11
- case status
12
- when :success
13
- assert(responses.first.successful?)
14
- when :redirect
15
- assert(responses.first.redirect?)
16
- when :not_found
17
- assert(responses.first.not_found?)
18
- when :error
19
- assert(responses.first.server_error?)
20
- else
21
- assert(false)
22
- end
23
- elsif status.is_a?(Fixnum)
24
- assert_equal(status, responses.first.status)
25
- end
26
- end
27
-
28
- # Asserts that the request has been redirected to the specified url.
29
- def assert_redirected_to(url)
30
- assert_equal(url, responses.first.location)
31
- end
32
-
33
- # Asserts that the specified cookie has been set to the specified value.
34
- def assert_cookie(name, value)
35
- assert cookies[name.to_s]
36
- assert_equal value, cookies[name.to_s]
37
- end
38
-
39
- # Asserts that there is no cookie set for the specified cookie
40
- def assert_no_cookie(name)
41
- assert !cookies[name.to_s]
42
- end
43
-
44
- def assert_difference(object, method = nil, difference = 1)
45
- start_count = object.send(method)
46
- yield
47
- object.reload if object.respond_to? :reload
48
- assert_equal start_count + difference, object.send(method)
49
- end
50
-
51
- end # TestAssertions
52
-
53
- end # Mack
54
-
55
- Test::Unit::TestCase.send(:include, Mack::TestAssertions)
@@ -1,192 +0,0 @@
1
- require "test/unit"
2
-
3
- module Mack
4
-
5
- module TestHelpers
6
-
7
- # Runs the given rake task. Takes an optional hash that mimics command line parameters.
8
- def rake_task(name, env = {}, tasks = File.join(File.dirname(__FILE__), "..", "mack_tasks.rb"))
9
- # set up the Rake application
10
- rake = Rake::Application.new
11
- Rake.application = rake
12
-
13
- load(tasks)
14
-
15
- # save the old ENV so we can revert it
16
- old_env = ENV.to_hash
17
- # add in the new ENV stuff
18
- env.each_pair {|k,v| ENV[k.to_s] = v}
19
-
20
- begin
21
- # run the rake task
22
- rake[name].invoke
23
-
24
- # yield for the tests
25
- yield if block_given?
26
-
27
- rescue Exception => e
28
- raise e
29
- ensure
30
- # empty out the ENV
31
- ENV.clear
32
- # revert to the ENV before the test started
33
- old_env.to_hash.each_pair {|k,v| ENV[k] = v}
34
-
35
- # get rid of the Rake application
36
- Rake.application = nil
37
- end
38
- end
39
-
40
- # Temporarily changes the application configuration. Changes are reverted after
41
- # the yield returns.
42
- def temp_app_config(options = {})
43
- app_config.load_hash(options, String.randomize)
44
- yield
45
- app_config.revert
46
- end
47
-
48
- def remote_test # :nodoc:
49
- if (app_config.run_remote_tests)
50
- yield
51
- end
52
- end
53
-
54
- # Retrieves an instance variable from the controller from a request.
55
- def assigns(key)
56
- $mack_app.instance_variable_get("@app").instance_variable_get("@response").instance_variable_get("@controller").instance_variable_get("@#{key}")
57
- end
58
-
59
- # Performs a 'get' request for the specified uri.
60
- def get(uri, options = {})
61
- build_response(request.get(uri, build_request_options(options)))
62
- end
63
-
64
- # Performs a 'put' request for the specified uri.
65
- def put(uri, options = {})
66
- build_response(request.put(uri, build_request_options({:input => options.to_params})))
67
- end
68
-
69
- # Performs a 'post' request for the specified uri.
70
- def post(uri, options = {})
71
- build_response(request.post(uri, build_request_options({:input => options.to_params})))
72
- end
73
-
74
- # Performs a 'delete' request for the specified uri.
75
- def delete(uri, options = {})
76
- build_response(request.delete(uri, build_request_options(options)))
77
- end
78
-
79
- # Returns a Rack::MockRequest. If there isn't one, a new one is created.
80
- def request
81
- @request ||= Rack::MockRequest.new(mack_app)
82
- end
83
-
84
- # Returns the last Rack::MockResponse that got generated by a call.
85
- def response
86
- responses.last
87
- end
88
-
89
- # Returns all the Rack::MockResponse objects that get generated by a call.
90
- def responses
91
- @responses
92
- end
93
-
94
- # Returns a Mack::Session from the request.
95
- def session # :nodoc:
96
- Cachetastic::Caches::MackSessionCache.get(cookies[app_config.mack.session_id])
97
- end
98
-
99
- # Used to create a 'session' around a block of code. This is great of 'integration' tests.
100
- def in_session
101
- @in_session = true
102
- clear_session
103
- yield
104
- clear_session
105
- @in_session = false
106
- end
107
-
108
- # Clears all the sessions.
109
- def clear_session
110
- Cachetastic::Caches::MackSessionCache.expire_all
111
- end
112
-
113
- # Returns a Hash of cookies from the response.
114
- def cookies
115
- test_cookies
116
- end
117
-
118
- # Sets a cookie to be used for the next request
119
- def set_cookie(name, value)
120
- test_cookies[name] = value
121
- end
122
-
123
- # Removes a cookie.
124
- def remove_cookie(name)
125
- test_cookies.delete(name)
126
- end
127
-
128
- def method_missing(sym, *args)
129
- sym = sym.to_s
130
- case sym
131
- when /^clean_(.+)/
132
- captures = sym.match(/^clean_(.+)/).captures
133
- thing = eval(captures.first)
134
- if File.exists?(thing)
135
- FileUtils.rm_rf(thing)
136
- end
137
- else
138
- raise NoMethodError.new(sym)
139
- end
140
- end
141
-
142
- private
143
- def test_cookies
144
- @test_cookies = {} if @test_cookies.nil?
145
- @test_cookies
146
- end
147
-
148
- def mack_app
149
- if $mack_app.nil?
150
- $mack_app = Rack::Recursive.new(Mack::Runner.new)
151
- end
152
- $mack_app
153
- end
154
-
155
- def build_request_options(options)
156
- {"HTTP_COOKIE" => test_cookies.join("%s=%s", "; ")}.merge(options)
157
- end
158
-
159
- def build_response(res)
160
- @responses = [res]
161
- strip_cookies_from_response(res)
162
- # only retry if it's a redirect request
163
- if res.redirect?
164
- until res.successful?
165
- [res].flatten.each do |r|
166
- strip_cookies_from_response(r)
167
- end
168
- res = request.get(res["Location"])
169
- @responses << res
170
- end
171
- end
172
- end
173
-
174
- def strip_cookies_from_response(res)
175
- unless res.original_headers["Set-Cookie"].nil?
176
- res.original_headers["Set-Cookie"].each do |ck|
177
- spt = ck.split("=")
178
- name = spt.first
179
- value = spt.last
180
- if name == app_config.mack.session_id
181
- value = nil unless @in_session
182
- end
183
- set_cookie(name, value)
184
- end
185
- end
186
- end
187
-
188
- end # TestHelpers
189
-
190
- end # Mack
191
-
192
- Test::Unit::TestCase.send(:include, Mack::TestHelpers)