radiant-templates-extension 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HELP_designer.textile +79 -0
- data/README.textile +123 -0
- data/Rakefile +136 -0
- data/VERSION +1 -0
- data/app/controllers/admin/part_types_controller.rb +8 -0
- data/app/controllers/admin/templates_controller.rb +38 -0
- data/app/helpers/admin/part_types_helper.rb +26 -0
- data/app/helpers/admin/templates_helper.rb +108 -0
- data/app/models/part_type.rb +14 -0
- data/app/models/template.rb +80 -0
- data/app/models/template_part.rb +21 -0
- data/app/views/admin/pages/_edit_template.html.haml +32 -0
- data/app/views/admin/pages/_edit_template_part.html.haml +20 -0
- data/app/views/admin/pages/_switch_templates.html.haml +23 -0
- data/app/views/admin/pages/_template_column.html.haml +3 -0
- data/app/views/admin/pages/_template_column_header.html.haml +1 -0
- data/app/views/admin/part_types/_form.html.haml +36 -0
- data/app/views/admin/part_types/_list.html.haml +23 -0
- data/app/views/admin/part_types/edit.html.haml +5 -0
- data/app/views/admin/part_types/index.html.haml +7 -0
- data/app/views/admin/part_types/new.html.haml +2 -0
- data/app/views/admin/part_types/remove.html.haml +15 -0
- data/app/views/admin/templates/_form.html.haml +65 -0
- data/app/views/admin/templates/_template_part.html.haml +21 -0
- data/app/views/admin/templates/_templates_css.html.haml +12 -0
- data/app/views/admin/templates/edit.html.haml +10 -0
- data/app/views/admin/templates/index.html.haml +47 -0
- data/app/views/admin/templates/new.html.haml +9 -0
- data/app/views/admin/templates/remove.html.haml +15 -0
- data/config/initializers/radiant_config.rb +3 -0
- data/config/locales/en.yml +32 -0
- data/config/routes.rb +7 -0
- data/db/migrate/001_create_templates.rb +17 -0
- data/db/migrate/002_create_template_parts.rb +15 -0
- data/db/migrate/003_rename_sublayout_column.rb +9 -0
- data/db/migrate/004_add_position_to_templates.rb +13 -0
- data/db/migrate/005_create_part_types.rb +17 -0
- data/db/migrate/006_add_description_to_template_parts.rb +9 -0
- data/db/migrate/007_add_page_class_name_to_templates.rb +9 -0
- data/db/migrate/008_add_index_to_templates.rb +9 -0
- data/db/migrate/009_create_default_part_types.rb +23 -0
- data/db/migrate/010_update_boolean_part_type.rb +9 -0
- data/db/migrate/011_add_timestamps.rb +19 -0
- data/lib/file_system/model/part_type_extensions.rb +19 -0
- data/lib/file_system/model/template_extensions.rb +52 -0
- data/lib/tasks/templates_extension_tasks.rake +28 -0
- data/lib/templates/associations.rb +7 -0
- data/lib/templates/controller_extensions.rb +20 -0
- data/lib/templates/helper.rb +75 -0
- data/lib/templates/page_extensions.rb +43 -0
- data/lib/templates/tags.rb +43 -0
- data/public/images/admin/menu_arrow.png +0 -0
- data/public/images/admin/move_higher.png +0 -0
- data/public/images/admin/move_lower.png +0 -0
- data/public/images/admin/move_to_bottom.png +0 -0
- data/public/images/admin/move_to_top.png +0 -0
- data/public/images/admin/part_type.png +0 -0
- data/public/images/admin/template.png +0 -0
- data/spec/controllers/admin_page_controller_extensions_spec.rb +61 -0
- data/spec/controllers/part_types_controller_spec.rb +89 -0
- data/spec/controllers/templates_controller_spec.rb +322 -0
- data/spec/datasets/part_types_dataset.rb +15 -0
- data/spec/datasets/templates_dataset.rb +34 -0
- data/spec/helpers/templates_helper_spec.rb +56 -0
- data/spec/models/page_extensions_spec.rb +9 -0
- data/spec/models/part_type_spec.rb +28 -0
- data/spec/models/tags_spec.rb +44 -0
- data/spec/models/template_part_spec.rb +37 -0
- data/spec/models/template_spec.rb +88 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +39 -0
- data/templates_extension.rb +83 -0
- data/vendor/plugins/acts_as_list/README +23 -0
- data/vendor/plugins/acts_as_list/init.rb +3 -0
- data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
- data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
- data/vendor/plugins/make_resourceful/DEFAULTS +148 -0
- data/vendor/plugins/make_resourceful/LICENSE +7 -0
- data/vendor/plugins/make_resourceful/README +239 -0
- data/vendor/plugins/make_resourceful/Rakefile +42 -0
- data/vendor/plugins/make_resourceful/VERSION +1 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb +87 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/controller.rb +5 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/fixtures.yml +10 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/functional_test.rb +57 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/helper.rb +2 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/migration.rb +13 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/model.rb +2 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/unit_test.rb +7 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view__form.haml +5 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_edit.haml +11 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_index.haml +5 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_new.haml +9 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_partial.haml +12 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_show.haml +14 -0
- data/vendor/plugins/make_resourceful/init.rb +3 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/base.rb +52 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/builder.rb +354 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/accessors.rb +346 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/actions.rb +92 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/callbacks.rb +51 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/responses.rb +118 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/urls.rb +137 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/maker.rb +83 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/response.rb +33 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/serialize.rb +181 -0
- data/vendor/plugins/make_resourceful/spec/accessors_spec.rb +473 -0
- data/vendor/plugins/make_resourceful/spec/actions_spec.rb +283 -0
- data/vendor/plugins/make_resourceful/spec/base_spec.rb +12 -0
- data/vendor/plugins/make_resourceful/spec/builder_spec.rb +332 -0
- data/vendor/plugins/make_resourceful/spec/callbacks_spec.rb +71 -0
- data/vendor/plugins/make_resourceful/spec/integration_spec.rb +396 -0
- data/vendor/plugins/make_resourceful/spec/maker_spec.rb +91 -0
- data/vendor/plugins/make_resourceful/spec/response_spec.rb +37 -0
- data/vendor/plugins/make_resourceful/spec/responses_spec.rb +314 -0
- data/vendor/plugins/make_resourceful/spec/rspec_on_rails/LICENSE +35 -0
- data/vendor/plugins/make_resourceful/spec/rspec_on_rails/redirect_to.rb +81 -0
- data/vendor/plugins/make_resourceful/spec/rspec_on_rails/render_template.rb +28 -0
- data/vendor/plugins/make_resourceful/spec/serialize_spec.rb +133 -0
- data/vendor/plugins/make_resourceful/spec/spec_helper.rb +279 -0
- data/vendor/plugins/make_resourceful/spec/urls_spec.rb +276 -0
- metadata +214 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'action_controller/url_rewriter'
|
2
|
+
|
3
|
+
class RedirectTo
|
4
|
+
def initialize(request, expected)
|
5
|
+
@expected = expected
|
6
|
+
@request = request
|
7
|
+
end
|
8
|
+
|
9
|
+
def matches?(response)
|
10
|
+
@redirected = response.redirect?
|
11
|
+
@actual = response.redirect_url
|
12
|
+
return false unless @redirected
|
13
|
+
if @expected.instance_of? Hash
|
14
|
+
return false unless @actual =~ %r{^\w+://#{@request.host}}
|
15
|
+
return false unless actual_redirect_to_valid_route
|
16
|
+
return actual_hash == expected_hash
|
17
|
+
else
|
18
|
+
return @actual == expected_url
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def actual_hash
|
23
|
+
hash_from_url @actual
|
24
|
+
end
|
25
|
+
|
26
|
+
def expected_hash
|
27
|
+
hash_from_url expected_url
|
28
|
+
end
|
29
|
+
|
30
|
+
def actual_redirect_to_valid_route
|
31
|
+
actual_hash
|
32
|
+
end
|
33
|
+
|
34
|
+
def hash_from_url(url)
|
35
|
+
query_hash(url).merge(path_hash(url)).with_indifferent_access
|
36
|
+
end
|
37
|
+
|
38
|
+
def path_hash(url)
|
39
|
+
path = url.sub(%r{^\w+://#{@request.host}}, "").split("?", 2)[0]
|
40
|
+
path = path.split("/")[1..-1] if ::Rails::VERSION::MINOR < 2
|
41
|
+
ActionController::Routing::Routes.recognize_path path
|
42
|
+
end
|
43
|
+
|
44
|
+
def query_hash(url)
|
45
|
+
query = url.split("?", 2)[1] || ""
|
46
|
+
if defined?(CGIMethods)
|
47
|
+
CGIMethods.parse_query_parameters(query)
|
48
|
+
else
|
49
|
+
ActionController::AbstractRequest.parse_query_parameters(query)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def expected_url
|
54
|
+
case @expected
|
55
|
+
when Hash
|
56
|
+
return ActionController::UrlRewriter.new(@request, {}).rewrite(@expected)
|
57
|
+
when :back
|
58
|
+
return @request.env['HTTP_REFERER']
|
59
|
+
when %r{^\w+://.*}
|
60
|
+
return @expected
|
61
|
+
else
|
62
|
+
return "http://#{@request.host}" + (@expected.split('')[0] == '/' ? '' : '/') + @expected
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def failure_message
|
67
|
+
if @redirected
|
68
|
+
return %Q{expected redirect to #{@expected.inspect}, got redirect to #{@actual.inspect}}
|
69
|
+
else
|
70
|
+
return %Q{expected redirect to #{@expected.inspect}, got no redirect}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def negative_failure_message
|
75
|
+
return %Q{expected not to be redirected to #{@expected.inspect}, but was} if @redirected
|
76
|
+
end
|
77
|
+
|
78
|
+
def description
|
79
|
+
"redirect to #{@actual.inspect}"
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
class RenderTemplate
|
3
|
+
|
4
|
+
def initialize(expected, controller)
|
5
|
+
@controller = controller
|
6
|
+
@expected = expected
|
7
|
+
end
|
8
|
+
|
9
|
+
def matches?(response)
|
10
|
+
@actual = response.rendered_file
|
11
|
+
full_path(@actual) == full_path(@expected)
|
12
|
+
end
|
13
|
+
|
14
|
+
def failure_message
|
15
|
+
"expected #{@expected.inspect}, got #{@actual.inspect}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def description
|
19
|
+
"render template #{@expected.inspect}"
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def full_path(path)
|
24
|
+
return nil if path.nil?
|
25
|
+
path.include?('/') ? path : "#{@controller.class.to_s.underscore.gsub('_controller','')}/#{path}"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,133 @@
|
|
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
|
@@ -0,0 +1,279 @@
|
|
1
|
+
$: << File.dirname(__FILE__) + '/../lib'
|
2
|
+
require 'rubygems'
|
3
|
+
%w[spec action_pack active_record resourceful/maker
|
4
|
+
action_controller action_controller/test_process action_controller/integration
|
5
|
+
spec/rspec_on_rails/redirect_to spec/rspec_on_rails/render_template].each &method(:require)
|
6
|
+
|
7
|
+
Spec::Runner.configure do |config|
|
8
|
+
config.mock_with :mocha
|
9
|
+
end
|
10
|
+
|
11
|
+
def should_be_called(&block)
|
12
|
+
pstub = stub
|
13
|
+
pstub.expects(:call).instance_eval(&(block || proc {}))
|
14
|
+
proc { |*args| pstub.call(*args) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def stub_model(name)
|
18
|
+
model = Class.new do
|
19
|
+
include Resourceful::Serialize::Model
|
20
|
+
|
21
|
+
def self.to_s
|
22
|
+
@name
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(attrs = {})
|
26
|
+
attrs.each do |k, v|
|
27
|
+
self.stubs(k).returns(v)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def inspect
|
32
|
+
"#<#{self.class.send(:instance_variable_get, '@name')}>"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
model.send(:instance_variable_set, '@name', name)
|
36
|
+
model
|
37
|
+
end
|
38
|
+
|
39
|
+
def stub_const(name)
|
40
|
+
unless Object.const_defined?(name)
|
41
|
+
obj = Object.new
|
42
|
+
obj.metaclass.send(:define_method, :to_s) { name.to_s }
|
43
|
+
obj.metaclass.send(:alias_method, :inspect, :to_s)
|
44
|
+
Object.const_set(name, obj)
|
45
|
+
end
|
46
|
+
Object.const_get(name)
|
47
|
+
end
|
48
|
+
|
49
|
+
def stub_list(size, name = nil, &block)
|
50
|
+
list = Array.new(size) { |i| name ? stub("#{name}_#{i}") : stub }
|
51
|
+
list.each(&block) if block
|
52
|
+
list
|
53
|
+
end
|
54
|
+
|
55
|
+
module Spec::Matchers
|
56
|
+
def have_any(&proc)
|
57
|
+
satisfy { |a| a.any?(&proc) }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
module ControllerMocks
|
62
|
+
def mock_kontroller(*to_extend)
|
63
|
+
options = to_extend.last.is_a?(Hash) ? to_extend.slice!(-1) : {}
|
64
|
+
@kontroller = Class.new
|
65
|
+
@kontroller.extend Resourceful::Maker
|
66
|
+
to_extend.each(&@kontroller.method(:extend))
|
67
|
+
|
68
|
+
@hidden_actions = Resourceful::ACTIONS.dup
|
69
|
+
@kontroller.stubs(:hidden_actions).returns(@hidden_actions)
|
70
|
+
@kontroller.stubs(:plural_action?).returns(false)
|
71
|
+
@kontroller.stubs(:include)
|
72
|
+
@kontroller.stubs(:before_filter)
|
73
|
+
@kontroller.stubs(:helper_method)
|
74
|
+
end
|
75
|
+
|
76
|
+
def mock_controller(*to_extend)
|
77
|
+
mock_kontroller
|
78
|
+
@controller = @kontroller.new
|
79
|
+
to_extend.each(&@controller.method(:extend))
|
80
|
+
end
|
81
|
+
|
82
|
+
def mock_builder(inherited = false)
|
83
|
+
@builder = stub
|
84
|
+
@builder.stubs(:response_for)
|
85
|
+
@builder.stubs(:apply)
|
86
|
+
@builder.stubs(:instance_eval).yields(@buildercc )
|
87
|
+
@builder.stubs(:inherited?).returns(inherited)
|
88
|
+
Resourceful::Base.stubs(:made_resourceful).returns([])
|
89
|
+
Resourceful::Builder.stubs(:new).returns(@builder)
|
90
|
+
end
|
91
|
+
|
92
|
+
def create_builder
|
93
|
+
@builder = Resourceful::Builder.new(@kontroller)
|
94
|
+
class << @builder
|
95
|
+
alias_method :made_resourceful, :instance_eval
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def responses
|
100
|
+
@kontroller.read_inheritable_attribute(:resourceful_responses)
|
101
|
+
end
|
102
|
+
|
103
|
+
def callbacks
|
104
|
+
@kontroller.read_inheritable_attribute(:resourceful_callbacks)
|
105
|
+
end
|
106
|
+
|
107
|
+
def parents
|
108
|
+
@kontroller.read_inheritable_attribute(:parents)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Evaluates the made_resourceful block of mod (a module)
|
112
|
+
# in the context of @builder.
|
113
|
+
# @builder should be initialized via create_builder.
|
114
|
+
def made_resourceful(mod)
|
115
|
+
mod.included(@builder)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
module RailsMocks
|
120
|
+
attr_reader :response, :request, :controller, :kontroller
|
121
|
+
|
122
|
+
def included(mod)
|
123
|
+
require 'ruby-debug'
|
124
|
+
debugger
|
125
|
+
end
|
126
|
+
|
127
|
+
def mock_resourceful(options = {}, &block)
|
128
|
+
options = {
|
129
|
+
:name => "things"
|
130
|
+
}.merge options
|
131
|
+
|
132
|
+
init_kontroller options
|
133
|
+
init_routes options
|
134
|
+
|
135
|
+
stub_const(options[:name].singularize.camelize)
|
136
|
+
kontroller.make_resourceful(&block)
|
137
|
+
|
138
|
+
init_controller options
|
139
|
+
end
|
140
|
+
|
141
|
+
def assigns(name)
|
142
|
+
controller.instance_variable_get("@#{name}")
|
143
|
+
end
|
144
|
+
|
145
|
+
def redirect_to(opts)
|
146
|
+
RedirectTo.new(request, opts)
|
147
|
+
end
|
148
|
+
|
149
|
+
def render_template(path)
|
150
|
+
RenderTemplate.new(path.to_s, @controller)
|
151
|
+
end
|
152
|
+
|
153
|
+
private
|
154
|
+
|
155
|
+
def init_kontroller(options)
|
156
|
+
@kontroller = Class.new ActionController::Base
|
157
|
+
@kontroller.extend Resourceful::Maker
|
158
|
+
|
159
|
+
@kontroller.metaclass.send(:define_method, :controller_name) { options[:name] }
|
160
|
+
@kontroller.metaclass.send(:define_method, :controller_path) { options[:name] }
|
161
|
+
@kontroller.metaclass.send(:define_method, :inspect) { "#{options[:name].camelize}Controller" }
|
162
|
+
@kontroller.metaclass.send(:alias_method, :to_s, :inspect)
|
163
|
+
|
164
|
+
@kontroller.send(:define_method, :controller_name) { options[:name] }
|
165
|
+
@kontroller.send(:define_method, :controller_path) { options[:name] }
|
166
|
+
@kontroller.send(:define_method, :inspect) { "#<#{options[:name].camelize}Controller>" }
|
167
|
+
@kontroller.send(:alias_method, :to_s, :inspect)
|
168
|
+
@kontroller.send(:include, ControllerMethods)
|
169
|
+
|
170
|
+
@kontroller
|
171
|
+
end
|
172
|
+
|
173
|
+
def init_routes(options)
|
174
|
+
ActionController::Routing::Routes.clear!
|
175
|
+
route_block = options[:routes] || proc { |map| map.resources options[:name] }
|
176
|
+
ActionController::Routing::Routes.draw(&route_block)
|
177
|
+
end
|
178
|
+
|
179
|
+
def init_controller(options)
|
180
|
+
@controller = kontroller.new
|
181
|
+
@request = ActionController::TestRequest.new
|
182
|
+
@response = ActionController::TestResponse.new
|
183
|
+
|
184
|
+
@controller.request = @request
|
185
|
+
@controller.response = @response
|
186
|
+
@request.accept = '*/*'
|
187
|
+
@request.env['HTTP_REFERER'] = 'http://test.host'
|
188
|
+
|
189
|
+
@controller
|
190
|
+
end
|
191
|
+
|
192
|
+
def action_params(action, params = {})
|
193
|
+
params.merge case action
|
194
|
+
when :show, :edit, :destroy: {:id => 12}
|
195
|
+
when :update: {:id => 12, :thing => {}}
|
196
|
+
when :create: {:thing => {}}
|
197
|
+
else {}
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def action_method(action)
|
202
|
+
method case action
|
203
|
+
when :index, :show, :edit, :new: :get
|
204
|
+
when :update: :put
|
205
|
+
when :create: :post
|
206
|
+
when :destroy: :delete
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
module ControllerMethods
|
211
|
+
def render(options=nil, deprecated_status=nil, &block)
|
212
|
+
unless block_given?
|
213
|
+
@template.metaclass.class_eval do
|
214
|
+
define_method :file_exists? do true end
|
215
|
+
define_method :render_file do |*args|
|
216
|
+
@first_render ||= args[0]
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
super(options, deprecated_status, &block)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
module Spec::Example::ExampleGroupMethods
|
227
|
+
def should_render_html(action)
|
228
|
+
it "should render HTML by default for #{action_string(action)}" do
|
229
|
+
action_method(action)[action, action_params(action)]
|
230
|
+
response.should be_success
|
231
|
+
response.content_type.should == 'text/html'
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
def should_render_js(action)
|
236
|
+
it "should render JS for #{action_string(action)}" do
|
237
|
+
action_method(action)[action, action_params(action, :format => 'js')]
|
238
|
+
response.should be_success
|
239
|
+
response.content_type.should == 'text/javascript'
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def shouldnt_render_xml(action)
|
244
|
+
it "should render XML for #{action_string(action)}" do
|
245
|
+
action_method(action)[action, action_params(action, :format => 'xml')]
|
246
|
+
response.should_not be_success
|
247
|
+
response.code.should == '406'
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
def action_string(action)
|
252
|
+
case action
|
253
|
+
when :index: "GET /things"
|
254
|
+
when :show: "GET /things/12"
|
255
|
+
when :edit: "GET /things/12/edit"
|
256
|
+
when :update: "PUT /things/12"
|
257
|
+
when :create: "POST /things"
|
258
|
+
when :new: "GET /things/new"
|
259
|
+
when :destroy: "DELETE /things/12"
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
module Spec::Example
|
265
|
+
class IntegrationExampleGroup < Test::Unit::TestCase
|
266
|
+
include ExampleMethods
|
267
|
+
class << self
|
268
|
+
include ExampleGroupMethods
|
269
|
+
end
|
270
|
+
|
271
|
+
def initialize(defined_description, &implementation)
|
272
|
+
super()
|
273
|
+
@_defined_description = defined_description
|
274
|
+
@_implementation = implementation
|
275
|
+
end
|
276
|
+
|
277
|
+
ExampleGroupFactory.register(:integration, self)
|
278
|
+
end
|
279
|
+
end
|