easy_admin_ui 0.5.9 → 0.5.11

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 (60) hide show
  1. data/VERSION +1 -1
  2. data/{vendor/plugins/make_resourceful/init.rb → config/initializers/make_resourceful.rb} +0 -0
  3. data/easy_admin_ui.gemspec +14 -60
  4. data/{vendor/plugins/make_resourceful/lib → lib}/resourceful/base.rb +0 -0
  5. data/{vendor/plugins/make_resourceful/lib → lib}/resourceful/builder.rb +0 -0
  6. data/{vendor/plugins/make_resourceful/lib → lib}/resourceful/default/accessors.rb +0 -0
  7. data/{vendor/plugins/make_resourceful/lib → lib}/resourceful/default/actions.rb +0 -0
  8. data/{vendor/plugins/make_resourceful/lib → lib}/resourceful/default/callbacks.rb +0 -0
  9. data/{vendor/plugins/make_resourceful/lib → lib}/resourceful/default/responses.rb +0 -0
  10. data/{vendor/plugins/make_resourceful/lib → lib}/resourceful/default/urls.rb +0 -0
  11. data/{vendor/plugins/make_resourceful/lib → lib}/resourceful/maker.rb +0 -0
  12. data/{vendor/plugins/make_resourceful/lib → lib}/resourceful/response.rb +0 -0
  13. data/{vendor/plugins/make_resourceful/lib → lib}/resourceful/serialize.rb +0 -0
  14. metadata +17 -63
  15. data/vendor/plugins/make_resourceful/.gitignore +0 -1
  16. data/vendor/plugins/make_resourceful/DEFAULTS +0 -148
  17. data/vendor/plugins/make_resourceful/LICENSE +0 -7
  18. data/vendor/plugins/make_resourceful/README.rdoc +0 -239
  19. data/vendor/plugins/make_resourceful/Rakefile +0 -31
  20. data/vendor/plugins/make_resourceful/VERSION +0 -1
  21. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb +0 -87
  22. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/controller.rb +0 -5
  23. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/fixtures.yml +0 -10
  24. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/functional_test.rb +0 -50
  25. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/helper.rb +0 -2
  26. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/migration.rb +0 -13
  27. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/model.rb +0 -2
  28. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/unit_test.rb +0 -7
  29. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view__form.haml +0 -5
  30. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_edit.haml +0 -11
  31. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_index.haml +0 -5
  32. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_new.haml +0 -9
  33. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_partial.haml +0 -12
  34. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_show.haml +0 -14
  35. data/vendor/plugins/make_resourceful/spec/accessors_spec.rb +0 -474
  36. data/vendor/plugins/make_resourceful/spec/actions_spec.rb +0 -310
  37. data/vendor/plugins/make_resourceful/spec/base_spec.rb +0 -12
  38. data/vendor/plugins/make_resourceful/spec/builder_spec.rb +0 -332
  39. data/vendor/plugins/make_resourceful/spec/callbacks_spec.rb +0 -71
  40. data/vendor/plugins/make_resourceful/spec/integration_spec.rb +0 -394
  41. data/vendor/plugins/make_resourceful/spec/maker_spec.rb +0 -91
  42. data/vendor/plugins/make_resourceful/spec/response_spec.rb +0 -37
  43. data/vendor/plugins/make_resourceful/spec/responses_spec.rb +0 -314
  44. data/vendor/plugins/make_resourceful/spec/rspec-rails/LICENSE +0 -37
  45. data/vendor/plugins/make_resourceful/spec/rspec-rails/redirect_to.rb +0 -113
  46. data/vendor/plugins/make_resourceful/spec/rspec-rails/render_template.rb +0 -90
  47. data/vendor/plugins/make_resourceful/spec/serialize_spec.rb +0 -133
  48. data/vendor/plugins/make_resourceful/spec/spec_helper.rb +0 -319
  49. data/vendor/plugins/make_resourceful/spec/urls_spec.rb +0 -282
  50. data/vendor/plugins/make_resourceful/spec/views/things/create.rjs +0 -1
  51. data/vendor/plugins/make_resourceful/spec/views/things/destroy.rjs +0 -1
  52. data/vendor/plugins/make_resourceful/spec/views/things/edit.html.erb +0 -4
  53. data/vendor/plugins/make_resourceful/spec/views/things/edit.rjs +0 -1
  54. data/vendor/plugins/make_resourceful/spec/views/things/index.html.erb +0 -4
  55. data/vendor/plugins/make_resourceful/spec/views/things/index.rjs +0 -1
  56. data/vendor/plugins/make_resourceful/spec/views/things/new.html.erb +0 -4
  57. data/vendor/plugins/make_resourceful/spec/views/things/new.rjs +0 -1
  58. data/vendor/plugins/make_resourceful/spec/views/things/show.html.erb +0 -4
  59. data/vendor/plugins/make_resourceful/spec/views/things/show.rjs +0 -1
  60. data/vendor/plugins/make_resourceful/spec/views/things/update.rjs +0 -1
@@ -1,113 +0,0 @@
1
- module Spec
2
- module Rails
3
- module Matchers
4
-
5
- class RedirectTo #:nodoc:
6
-
7
- def initialize(request, expected)
8
- @expected = expected
9
- @request = request
10
- end
11
-
12
- def matches?(response)
13
- @redirected = response.redirect?
14
- @actual = response.redirect_url
15
- return false unless @redirected
16
- if @expected.instance_of? Hash
17
- return false unless @actual =~ %r{^\w+://#{@request.host}}
18
- return false unless actual_redirect_to_valid_route
19
- return actual_hash == expected_hash
20
- else
21
- return @actual == expected_url
22
- end
23
- end
24
-
25
- def actual_hash
26
- hash_from_url @actual
27
- end
28
-
29
- def expected_hash
30
- hash_from_url expected_url
31
- end
32
-
33
- def actual_redirect_to_valid_route
34
- actual_hash
35
- end
36
-
37
- def hash_from_url(url)
38
- query_hash(url).merge(path_hash(url)).with_indifferent_access
39
- end
40
-
41
- def path_hash(url)
42
- path = url.sub(%r{^\w+://#{@request.host}(?::\d+)?}, "").split("?", 2)[0]
43
- ActionController::Routing::Routes.recognize_path path
44
- end
45
-
46
- def query_hash(url)
47
- query = url.split("?", 2)[1] || ""
48
- QueryParameterParser.parse_query_parameters(query, @request)
49
- end
50
-
51
- def expected_url
52
- case @expected
53
- when Hash
54
- return ActionController::UrlRewriter.new(@request, {}).rewrite(@expected)
55
- when :back
56
- return @request.env['HTTP_REFERER']
57
- when %r{^\w+://.*}
58
- return @expected
59
- else
60
- return "http://#{@request.host}" + (@expected.split('')[0] == '/' ? '' : '/') + @expected
61
- end
62
- end
63
-
64
- def failure_message
65
- if @redirected
66
- return %Q{expected redirect to #{@expected.inspect}, got redirect to #{@actual.inspect}}
67
- else
68
- return %Q{expected redirect to #{@expected.inspect}, got no redirect}
69
- end
70
- end
71
-
72
- def negative_failure_message
73
- return %Q{expected not to be redirected to #{@expected.inspect}, but was} if @redirected
74
- end
75
-
76
- def description
77
- "redirect to #{@actual.inspect}"
78
- end
79
-
80
- class QueryParameterParser
81
- def self.parse_query_parameters(query, request)
82
- if defined?(CGIMethods)
83
- CGIMethods.parse_query_parameters(query)
84
- else
85
- request.class.parse_query_parameters(query)
86
- end
87
- end
88
- end
89
- end
90
-
91
- # :call-seq:
92
- # response.should redirect_to(url)
93
- # response.should redirect_to(:action => action_name)
94
- # response.should redirect_to(:controller => controller_name, :action => action_name)
95
- # response.should_not redirect_to(url)
96
- # response.should_not redirect_to(:action => action_name)
97
- # response.should_not redirect_to(:controller => controller_name, :action => action_name)
98
- #
99
- # Passes if the response is a redirect to the url, action or controller/action.
100
- # Useful in controller specs (integration or isolation mode).
101
- #
102
- # == Examples
103
- #
104
- # response.should redirect_to("path/to/action")
105
- # response.should redirect_to("http://test.host/path/to/action")
106
- # response.should redirect_to(:action => 'list')
107
- def redirect_to(opts)
108
- RedirectTo.new(request, opts)
109
- end
110
- end
111
-
112
- end
113
- end
@@ -1,90 +0,0 @@
1
- module Spec
2
- module Rails
3
- module Matchers
4
-
5
- class RenderTemplate #:nodoc:
6
-
7
- def initialize(expected, controller)
8
- @controller = controller
9
- @expected = expected
10
- end
11
-
12
- def matches?(response)
13
-
14
- if response.respond_to?(:rendered_file)
15
- @actual = response.rendered_file
16
- else
17
- @actual = response.rendered_template.to_s
18
- end
19
- return false if @actual.blank?
20
- given_controller_path, given_file = path_and_file(@actual)
21
- expected_controller_path, expected_file = path_and_file(@expected)
22
- given_controller_path == expected_controller_path && given_file.match(expected_file)
23
- end
24
-
25
- def failure_message
26
- "expected #{@expected.inspect}, got #{@actual.inspect}"
27
- end
28
-
29
- def negative_failure_message
30
- "expected not to render #{@expected.inspect}, but did"
31
- end
32
-
33
- def description
34
- "render template #{@expected.inspect}"
35
- end
36
-
37
- private
38
- def path_and_file(path)
39
- parts = path.split('/')
40
- file = parts.pop
41
- controller = parts.empty? ? current_controller_path : parts.join('/')
42
- return controller, file
43
- end
44
-
45
- def controller_path_from(path)
46
- parts = path.split('/')
47
- parts.pop
48
- parts.join('/')
49
- end
50
-
51
- def current_controller_path
52
- @controller.class.to_s.underscore.gsub(/_controller$/,'')
53
- end
54
-
55
- end
56
-
57
- # :call-seq:
58
- # response.should render_template(path)
59
- # response.should_not render_template(path)
60
- #
61
- # Passes if the specified template is rendered by the response.
62
- # Useful in controller specs (integration or isolation mode).
63
- #
64
- # <code>path</code> can include the controller path or not. It
65
- # can also include an optional extension (no extension assumes .rhtml).
66
- #
67
- # Note that partials must be spelled with the preceding underscore.
68
- #
69
- # == Examples
70
- #
71
- # response.should render_template('list')
72
- # response.should render_template('same_controller/list')
73
- # response.should render_template('other_controller/list')
74
- #
75
- # #rjs
76
- # response.should render_template('list.rjs')
77
- # response.should render_template('same_controller/list.rjs')
78
- # response.should render_template('other_controller/list.rjs')
79
- #
80
- # #partials
81
- # response.should render_template('_a_partial')
82
- # response.should render_template('same_controller/_a_partial')
83
- # response.should render_template('other_controller/_a_partial')
84
- def render_template(path)
85
- RenderTemplate.new(path.to_s, @controller)
86
- end
87
-
88
- end
89
- end
90
- end
@@ -1,133 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe Resourceful::Serialize, ".normalize_attributes" do
4
- it "should return nil if given nil" do
5
- Resourceful::Serialize.normalize_attributes(nil).should be_nil
6
- end
7
-
8
- it "should return a basic hash if given a non-injectable attribute" do
9
- Resourceful::Serialize.normalize_attributes(:foo).should == {:foo => nil}
10
- Resourceful::Serialize.normalize_attributes(12).should == {12 => nil}
11
- end
12
-
13
- it "should return a basic hash with a symbol key if given a string attribute" do
14
- Resourceful::Serialize.normalize_attributes("foo").should == {:foo => nil}
15
- end
16
-
17
- it "should preserve hashes" do
18
- Resourceful::Serialize.normalize_attributes({:foo => nil, :bar => nil, :baz => nil}).should ==
19
- {:foo => nil, :bar => nil, :baz => nil}
20
- Resourceful::Serialize.normalize_attributes({:foo => 3, :bar => 1, :baz => 4}).should ==
21
- {:foo => 3, :bar => 1, :baz => 4}
22
- Resourceful::Serialize.normalize_attributes({:foo => 3, :bar => 1, :baz => [:foo, :bar]}).should ==
23
- {:foo => 3, :bar => 1, :baz => [:foo, :bar]}
24
- end
25
-
26
- it "should merge injectable attributes into one big hash" do
27
- Resourceful::Serialize.normalize_attributes([:foo, :bar, :baz]).should ==
28
- {:foo => nil, :bar => nil, :baz => nil}
29
- Resourceful::Serialize.normalize_attributes([:foo, :bar, {:baz => nil},
30
- :boom, {:bop => nil, :blat => nil}]).should ==
31
- {:foo => nil, :bar => nil, :baz => nil, :boom => nil, :bop => nil, :blat => nil}
32
- Resourceful::Serialize.normalize_attributes([:foo, :bar, {:baz => 12},
33
- :boom, {:bop => "foo", :blat => [:fee, :fi, :fo]}]).should ==
34
- {:foo => nil, :bar => nil, :baz => 12, :boom => nil, :bop => "foo", :blat => [:fee, :fi, :fo]}
35
- end
36
- end
37
-
38
- describe Array, " of non-serializable objects" do
39
- before :each do
40
- @array = [1, 2, 3, 4, "foo"]
41
- end
42
-
43
- it "should return itself for #to_serializable" do
44
- @array.to_serializable(nil).should == @array
45
- end
46
-
47
- it "should raise an error for #serialize" do
48
- lambda { @array.serialize(:yaml, :attributes => [:foo]) }.should raise_error("Not all elements respond to to_serializable")
49
- end
50
- end
51
-
52
- describe Array, " of serializable objects" do
53
- before :each do
54
- @cat = stub_model("Cat")
55
- @dog = stub_model("Dog")
56
- @array = %w{brown yellow green}.zip(%w{rex rover fido}).
57
- map { |c, d| @cat.new(:fur => c, :friend => @dog.new(:name => d)) }
58
- end
59
-
60
- it "should return an array of serializable hashes for #to_serializable" do
61
- @array.to_serializable([:fur]).should == [{'fur' => 'brown'}, {'fur' => 'yellow'}, {'fur' => 'green'}]
62
- end
63
-
64
- it "should follow deep attributes for #to_serializable" do
65
- @array.to_serializable([:fur, {:friend => :name}]).should ==
66
- [{'fur' => 'brown', 'friend' => {'name' => 'rex'}},
67
- {'fur' => 'yellow', 'friend' => {'name' => 'rover'}},
68
- {'fur' => 'green', 'friend' => {'name' => 'fido'}}]
69
- end
70
-
71
- it "should raise an error if #serialize is called without the :attributes option" do
72
- lambda { @array.serialize(:yaml, {}) }.should raise_error("Must specify :attributes option")
73
- end
74
-
75
- it "should serialize to a hash with a pluralized root for #serialize" do
76
- YAML.load(@array.serialize(:yaml, :attributes => [:fur, {:friend => :name}])).should ==
77
- {"cats" => [{'fur' => 'brown', 'friend' => {'name' => 'rex'}},
78
- {'fur' => 'yellow', 'friend' => {'name' => 'rover'}},
79
- {'fur' => 'green', 'friend' => {'name' => 'fido'}}]}
80
- end
81
-
82
- it "should serialize to an XML document with a pluralized root for #serialize(:xml, ...)" do
83
- doc = REXML::Document.new(@array.serialize(:xml, :attributes => [:fur, {:friend => :name}]),
84
- :ignore_whitespace_nodes => :all)
85
- doc.root.name.should == "cats"
86
- cats = doc.get_elements('/cats/cat')
87
- cats.size.should == 3
88
- cats.zip(%w{brown yellow green}, %w{rex rover fido}) do |cat, fur, dog|
89
- cat.children.find { |e| e.name == "fur" }.text.should == fur
90
- cat.children.find { |e| e.name == "friend" }.children[0].text.should == dog
91
- end
92
- end
93
- end
94
-
95
- describe ActiveRecord::Base, " with a few attributes and an association" do
96
- before :each do
97
- @person = stub_model("Person")
98
- @party_hat = stub_model("PartyHat")
99
- @model = @person.new(:name => "joe", :eye_color => "blue", :hairs => 567,
100
- :party_hat => @party_hat.new(:color => 'blue', :size => 12, :pattern => 'stripey'))
101
- end
102
-
103
- it "should raise an error if #to_serializable is called without attributes" do
104
- lambda { @model.to_serializable(nil) }.should raise_error("Must specify attributes for #<Person>.to_serializable")
105
- end
106
-
107
- it "should return an attributes hash for #to_serializable" do
108
- @model.to_serializable([:name, :hairs, {:party_hat => [:color, :size]}]).should ==
109
- {'name' => 'joe', 'hairs' => 567, 'party_hat' => {
110
- 'color' => 'blue', 'size' => 12
111
- }}
112
- end
113
-
114
- it "should raise an error if #serialize is called without the :attributes option" do
115
- lambda { @model.serialize(:yaml, {}) }.should raise_error("Must specify :attributes option")
116
- end
117
-
118
- it "should serialize to a hash for #serialize" do
119
- YAML.load(@model.serialize(:yaml, :attributes => [:hairs, :eye_color, {:party_hat => :size}])).should ==
120
- {"person" => {'hairs' => 567, 'eye_color' => 'blue', 'party_hat' => {'size' => 12}}}
121
- end
122
-
123
- it "should serialize to an XML document for #serialize(:xml, ...)" do
124
- doc = REXML::Document.new(@model.serialize(:xml, :attributes => [:name, :eye_color, {:party_hat => :pattern}]),
125
- :ignore_whitespace_nodes => :all)
126
- doc.root.name.should == "person"
127
- doc.root.children.find { |e| e.name == "name" }.text.should == "joe"
128
- doc.root.children.find { |e| e.name == "eye-color" }.text.should == "blue"
129
-
130
- hat = doc.root.children.find { |e| e.name == "party-hat" }
131
- hat.children.find { |e| e.name == "pattern" }.text.should == "stripey"
132
- end
133
- end
@@ -1,319 +0,0 @@
1
- $: << File.dirname(__FILE__) + '/../lib'
2
-
3
- require 'rubygems'
4
- %w[spec rails/version action_pack active_record resourceful/maker
5
- action_controller action_controller/test_process action_controller/integration
6
- spec/rspec-rails/redirect_to spec/rspec-rails/render_template].each &method(:require)
7
-
8
- Spec::Runner.configure do |config|
9
- config.mock_with :mocha
10
- end
11
-
12
- module MetaClass
13
- def metaclass
14
- class << self; self; end
15
- end
16
- end
17
-
18
- def should_be_called(&block)
19
- pstub = stub
20
- pstub.expects(:call).instance_eval(&(block || proc {}))
21
- proc { |*args| pstub.call(*args) }
22
- end
23
-
24
- def stub_model(name)
25
- model = Class.new do
26
- include Resourceful::Serialize::Model
27
-
28
- def self.to_s
29
- @name
30
- end
31
-
32
- def initialize(attrs = {})
33
- attrs.each do |k, v|
34
- self.stubs(k).returns(v)
35
- end
36
- end
37
-
38
- def inspect
39
- "#<#{self.class.send(:instance_variable_get, '@name')}>"
40
- end
41
- end
42
- model.send(:instance_variable_set, '@name', name)
43
- model
44
- end
45
-
46
- def stub_const(name)
47
- unless Object.const_defined?(name)
48
- obj = Object.new
49
- obj.extend MetaClass
50
- obj.metaclass.send(:define_method, :to_s) { name.to_s }
51
- obj.metaclass.send(:alias_method, :inspect, :to_s)
52
- Object.const_set(name, obj)
53
- end
54
- Object.const_get(name)
55
- end
56
-
57
- def stub_list(size, name = nil, &block)
58
- list = Array.new(size) { |i| name ? stub("#{name}_#{i}") : stub }
59
- list.each(&block) if block
60
- list
61
- end
62
-
63
- module Spec::Matchers
64
- def have_any(&proc)
65
- satisfy { |a| a.any?(&proc) }
66
- end
67
- end
68
-
69
- module ControllerMocks
70
- def mock_kontroller(*to_extend)
71
- options = to_extend.last.is_a?(Hash) ? to_extend.slice!(-1) : {}
72
- @kontroller = Class.new
73
- @kontroller.extend Resourceful::Maker
74
- to_extend.each(&@kontroller.method(:extend))
75
-
76
- @hidden_actions = Resourceful::ACTIONS.dup
77
- @kontroller.stubs(:hidden_actions).returns(@hidden_actions)
78
- @kontroller.stubs(:plural_action?).returns(false)
79
- @kontroller.stubs(:include)
80
- @kontroller.stubs(:before_filter)
81
- @kontroller.stubs(:helper_method)
82
- end
83
-
84
- def mock_controller(*to_extend)
85
- mock_kontroller
86
- @controller = @kontroller.new
87
- to_extend.each(&@controller.method(:extend))
88
- end
89
-
90
- def mock_builder(inherited = false)
91
- @builder = stub
92
- @builder.stubs(:response_for)
93
- @builder.stubs(:apply)
94
- @builder.stubs(:instance_eval).yields(@buildercc )
95
- @builder.stubs(:inherited?).returns(inherited)
96
- Resourceful::Base.stubs(:made_resourceful).returns([])
97
- Resourceful::Builder.stubs(:new).returns(@builder)
98
- end
99
-
100
- def create_builder
101
- @builder = Resourceful::Builder.new(@kontroller)
102
- class << @builder
103
- alias_method :made_resourceful, :instance_eval
104
- end
105
- end
106
-
107
- def responses
108
- @kontroller.resourceful_responses
109
- end
110
-
111
- def callbacks
112
- @kontroller.resourceful_callbacks
113
- end
114
-
115
- def parents
116
- @kontroller.parents
117
- end
118
-
119
- # Evaluates the made_resourceful block of mod (a module)
120
- # in the context of @builder.
121
- # @builder should be initialized via create_builder.
122
- def made_resourceful(mod)
123
- mod.included(@builder)
124
- end
125
- end
126
-
127
- module RailsMocks
128
- attr_reader :response, :request, :controller, :kontroller
129
-
130
- def included(mod)
131
- require 'ruby-debug'
132
- debugger
133
- end
134
-
135
- def mock_resourceful(options = {}, &block)
136
- options = {
137
- :name => "things"
138
- }.merge options
139
-
140
- init_kontroller options
141
- init_routes options
142
-
143
- stub_const(options[:name].singularize.camelize)
144
- kontroller.make_resourceful(&block)
145
-
146
- init_controller options
147
- end
148
-
149
- def assigns(name)
150
- controller.instance_variable_get("@#{name}")
151
- end
152
-
153
- def redirect_to(opts)
154
- Spec::Rails::Matchers::RedirectTo.new(request, opts)
155
- end
156
-
157
- def render_template(path)
158
- Spec::Rails::Matchers::RenderTemplate.new(path.to_s, @controller)
159
- end
160
-
161
- private
162
-
163
- def init_kontroller(options)
164
- @kontroller = Class.new ActionController::Base
165
- @kontroller.extend Resourceful::Maker
166
- @kontroller.extend MetaClass
167
-
168
- @kontroller.metaclass.send(:define_method, :controller_name) { options[:name] }
169
- @kontroller.metaclass.send(:define_method, :controller_path) { options[:name] }
170
- @kontroller.metaclass.send(:define_method, :inspect) { "#{options[:name].camelize}Controller" }
171
- @kontroller.metaclass.send(:alias_method, :to_s, :inspect)
172
-
173
- @kontroller.send(:define_method, :controller_name) { options[:name] }
174
- @kontroller.send(:define_method, :controller_path) { options[:name] }
175
- @kontroller.send(:define_method, :inspect) { "#<#{options[:name].camelize}Controller>" }
176
- @kontroller.send(:alias_method, :to_s, :inspect)
177
- @kontroller.send(:include, ControllerMethods)
178
- @kontroller.send(:view_paths=, [File.join(File.dirname(__FILE__), 'views')])
179
-
180
- @kontroller
181
- end
182
-
183
- def init_routes(options)
184
- ActionController::Routing::Routes.clear!
185
- route_block = options[:routes] || proc { |map| map.resources options[:name] }
186
- ActionController::Routing::Routes.draw(&route_block)
187
- end
188
-
189
- def init_controller(options)
190
- @controller = kontroller.new
191
- @request = ActionController::TestRequest.new
192
- @response = ActionController::TestResponse.new
193
-
194
- @controller.request = @request
195
- @controller.response = @response
196
- @request.accept = '*/*'
197
- @request.env['HTTP_REFERER'] = 'http://test.host'
198
-
199
- @controller
200
- end
201
-
202
- def action_params(action, params = {})
203
- params.merge case action
204
- when :show, :edit, :destroy: {:id => 12}
205
- when :update: {:id => 12, :thing => {}}
206
- when :create: {:thing => {}}
207
- else {}
208
- end
209
- end
210
-
211
- def action_method(action)
212
- method case action
213
- when :index, :show, :edit, :new: :get
214
- when :update: :put
215
- when :create: :post
216
- when :destroy: :delete
217
- end
218
- end
219
-
220
- module ControllerMethods
221
- # From rspec-rails ControllerExampleGroup
222
-
223
- def render(options=nil, deprecated_status_or_extra_options=nil, &block)
224
- if ::Rails::VERSION::STRING >= '2.0.0' && deprecated_status_or_extra_options.nil?
225
- deprecated_status_or_extra_options = {}
226
- end
227
-
228
- unless block_given?
229
- if @template.respond_to?(:finder)
230
- (class << @template.finder; self; end).class_eval do
231
- define_method :file_exists? do; true; end
232
- end
233
- else
234
- (class << @template; self; end).class_eval do
235
- define_method :file_exists? do; true; end
236
- end
237
- end
238
- (class << @template; self; end).class_eval do
239
- define_method :render_file do |*args|
240
- @first_render ||= args[0] unless args[0] =~ /^layouts/
241
- @_first_render ||= args[0] unless args[0] =~ /^layouts/
242
- end
243
-
244
- define_method :_pick_template do |*args|
245
- @_first_render ||= args[0] unless args[0] =~ /^layouts/
246
- PickedTemplate.new
247
- end
248
- end
249
- end
250
-
251
- super(options, deprecated_status_or_extra_options, &block)
252
- end
253
-
254
- class PickedTemplate
255
- def render_template(*ignore_args); end
256
- def render_partial(*ignore_args); end
257
- end
258
- end
259
-
260
- end
261
-
262
- module Spec::Example::ExampleGroupMethods
263
- def should_render_html(action)
264
- it "should render HTML by default for #{action_string(action)}" do
265
- action_method(action)[action, action_params(action)]
266
- response.body.should include("as HTML")
267
- response.content_type.should == 'text/html'
268
- end
269
- end
270
-
271
- def should_render_js(action)
272
- it "should render JS for #{action_string(action)}" do
273
- action_method(action)[action, action_params(action, :format => 'js')]
274
- response.body.should include("insert(\"#{action}")
275
- response.should be_success
276
- response.content_type.should == 'text/javascript'
277
- end
278
- end
279
-
280
- def shouldnt_render_xml(action)
281
- it "shouldn't render XML for #{action_string(action)}" do
282
- action_method(action)[action, action_params(action, :format => 'xml')]
283
- response.should_not be_success
284
- response.code.should == '406'
285
- end
286
- end
287
-
288
- def action_string(action)
289
- case action
290
- when :index: "GET /things"
291
- when :show: "GET /things/12"
292
- when :edit: "GET /things/12/edit"
293
- when :update: "PUT /things/12"
294
- when :create: "POST /things"
295
- when :new: "GET /things/new"
296
- when :destroy: "DELETE /things/12"
297
- end
298
- end
299
- end
300
-
301
- module Spec::Example
302
- class IntegrationExampleGroup < Spec::Example::ExampleGroup
303
- include ActionController::TestProcess
304
- include ActionController::Assertions
305
- include RailsMocks
306
-
307
- # Need this helper, because we made current_objects private
308
- def current_objects
309
- controller.instance_eval("current_objects")
310
- end
311
-
312
- # Need this helper, because we made current_object private
313
- def current_object
314
- controller.instance_eval("current_object")
315
- end
316
-
317
- ExampleGroupFactory.register(:integration, self)
318
- end
319
- end