active_presenters 1.0.1.5 → 1.0.1.6
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.
- data/lib/active_presenter_base.rb +14 -7
- data/lib/tasks/rubyforge_config.yml +1 -1
- metadata +2 -6
- data/test/active_presenters_test.rb +0 -93
- data/test/models.rb +0 -59
- data/test/presenters.rb +0 -11
- data/test/proxy_test.rb +0 -75
@@ -95,43 +95,43 @@ module ActivePresenter
|
|
95
95
|
eval %{
|
96
96
|
unless method_defined?(:index_path)
|
97
97
|
def index_path
|
98
|
-
#{self.plural}_path#{self.
|
98
|
+
#{self.plural}_path#{self.nested_resource_path_string}
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
102
|
unless method_defined?(:show_path)
|
103
103
|
def show_path
|
104
|
-
#{self.singular}_path
|
104
|
+
#{self.singular}_path#{self.nested_resource_path_string(true)}
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
108
|
unless method_defined?(:new_path)
|
109
109
|
def new_path
|
110
|
-
new_#{self.singular}_path#{self.
|
110
|
+
new_#{self.singular}_path#{self.nested_resource_path_string}
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
114
|
unless method_defined?(:create_path)
|
115
115
|
def create_path
|
116
|
-
#{self.plural}_path#{self.
|
116
|
+
#{self.plural}_path#{self.nested_resource_path_string}
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
unless method_defined?(:edit_path)
|
121
121
|
def edit_path
|
122
|
-
edit_#{self.singular}_path
|
122
|
+
edit_#{self.singular}_path#{self.nested_resource_path_string(true)}
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
126
|
unless method_defined?(:update_path)
|
127
127
|
def update_path
|
128
|
-
#{self.singular}_path
|
128
|
+
#{self.singular}_path#{self.nested_resource_path_string(true)}
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
132
|
unless method_defined?(:destroy_path)
|
133
133
|
def destroy_path
|
134
|
-
#{self.singular}_path
|
134
|
+
#{self.singular}_path#{self.nested_resource_path_string(true)}
|
135
135
|
end
|
136
136
|
end
|
137
137
|
}
|
@@ -140,6 +140,13 @@ module ActivePresenter
|
|
140
140
|
|
141
141
|
end
|
142
142
|
|
143
|
+
def nested_resource_path_string(include_self = false)
|
144
|
+
x = self.model.nested_resource.nil? ? '' : "self.model.nested_resource"
|
145
|
+
x << (x.blank? ? '' : ", ") << "self.model" if include_self
|
146
|
+
x = "(#{x})" unless x.blank?
|
147
|
+
x
|
148
|
+
end
|
149
|
+
|
143
150
|
def plural
|
144
151
|
self.model_underscore.pluralize
|
145
152
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: active_presenters
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0.1.
|
7
|
-
date: 2007-
|
6
|
+
version: 1.0.1.6
|
7
|
+
date: 2007-10-02 00:00:00 -04:00
|
8
8
|
summary: active_presenters
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -44,10 +44,6 @@ files:
|
|
44
44
|
- lib/presentable.rb
|
45
45
|
- lib/proxy.rb
|
46
46
|
- lib/tasks/rubyforge_config.yml
|
47
|
-
- test/active_presenters_test.rb
|
48
|
-
- test/models.rb
|
49
|
-
- test/presenters.rb
|
50
|
-
- test/proxy_test.rb
|
51
47
|
test_files: []
|
52
48
|
|
53
49
|
rdoc_options: []
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
ENV["RAILS_ENV"] = "test"
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
|
4
|
-
require File.expand_path(File.dirname(__FILE__) + "/../init")
|
5
|
-
require File.expand_path(File.dirname(__FILE__) + "/models")
|
6
|
-
require File.expand_path(File.dirname(__FILE__) + "/presenters")
|
7
|
-
|
8
|
-
ActionController::Routing::Routes.draw do |map|
|
9
|
-
map.resources :blog_posts
|
10
|
-
map.resources :blog_users
|
11
|
-
map.resources :blog_comments
|
12
|
-
end
|
13
|
-
|
14
|
-
class ActivePresentersTest < Test::Unit::TestCase
|
15
|
-
include ActionView::Helpers::TagHelper # link_to
|
16
|
-
include ActionView::Helpers::UrlHelper # url_for
|
17
|
-
include ActionController::UrlWriter # named routes
|
18
|
-
include ActionView::Helpers::TextHelper # link_to
|
19
|
-
include ActionView::Helpers::FormHelper
|
20
|
-
include ActionView::Helpers::FormTagHelper
|
21
|
-
include ActionView::Helpers::FormOptionsHelper
|
22
|
-
|
23
|
-
def test_base_presenter_built
|
24
|
-
bp = BlogPost.build_new
|
25
|
-
p = bp.presenter
|
26
|
-
assert_presenter_basics(bp, p)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_default_presenter_built
|
30
|
-
bc = BlogComment.build_new
|
31
|
-
p = bc.presenter
|
32
|
-
assert_presenter_basics(bc, p)
|
33
|
-
assert p.is_a?(BlogCommentPresenter)
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_custom_presenter_built
|
37
|
-
bu = BlogUser.build_new
|
38
|
-
p = bu.presenter
|
39
|
-
assert_presenter_basics(bu, p, "special_foo_presenter")
|
40
|
-
assert p.is_a?(SpecialFooPresenter)
|
41
|
-
assert_equal "Hello World!", p.show_link_text
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_poro_presenter_built
|
45
|
-
poro = Poro.new
|
46
|
-
p = poro.presenter
|
47
|
-
assert_presenter_basics(poro, p)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_ar_resource_methods_built
|
51
|
-
bp = BlogPost.build_new
|
52
|
-
p = bp.presenter
|
53
|
-
assert bp.is_restful?
|
54
|
-
assert_nil bp.nested_resource
|
55
|
-
rest_verbs.each_pair do |verb, meth|
|
56
|
-
assert p.respond_to?("#{verb}_link_text")
|
57
|
-
assert_equal verb.to_s, p.send("#{verb}_link_text")
|
58
|
-
assert p.respond_to?("#{verb}_link_options")
|
59
|
-
assert_equal({:method => meth.to_sym}, p.send("#{verb}_link_options")) unless verb == :destroy
|
60
|
-
assert_equal({:method => meth.to_sym, :confirm => 'Are you sure?', :method => :delete}, p.send("#{verb}_link_options")) if verb == :destroy
|
61
|
-
assert p.respond_to?("#{verb}_link")
|
62
|
-
assert_equal link_to(h("#{verb}"), p.send("#{verb}_path"), p.send("#{verb}_link_options")), p.send("#{verb}_link")
|
63
|
-
assert p.respond_to?("#{verb}_path")
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_ar_resource_methods_not_built
|
68
|
-
bp = Poro.new
|
69
|
-
p = bp.presenter
|
70
|
-
rest_verbs.each_pair do |verb, meth|
|
71
|
-
assert !p.respond_to?("#{verb}_link_text")
|
72
|
-
assert !p.respond_to?("#{verb}_link_options")
|
73
|
-
assert !p.respond_to?("#{verb}_link")
|
74
|
-
assert !p.respond_to?("#{verb}_path")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def rest_verbs
|
79
|
-
ActivePresenter::REST_VERBS
|
80
|
-
end
|
81
|
-
|
82
|
-
def assert_presenter_basics(model, presenter, presenter_name = "#{model.class.to_s.underscore.to_sym}_presenter")
|
83
|
-
m_underscore_sym = model.class.to_s.underscore.to_sym
|
84
|
-
assert model.is_presentable?
|
85
|
-
assert_equal presenter_name, model.presenter_name
|
86
|
-
assert_not_nil presenter
|
87
|
-
assert presenter.is_a?(ActivePresenter::Base)
|
88
|
-
assert_equal model, presenter.model
|
89
|
-
assert presenter.respond_to?(m_underscore_sym)
|
90
|
-
assert_equal presenter.model, presenter.send(m_underscore_sym)
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
data/test/models.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
class BlogPost < ActiveRecord::Base
|
2
|
-
|
3
|
-
attr_accessor :title
|
4
|
-
attr_accessor :body
|
5
|
-
attr_accessor :created_at
|
6
|
-
attr_accessor :updated_at
|
7
|
-
attr_accessor :id
|
8
|
-
|
9
|
-
def initialize(hsh = {})
|
10
|
-
hsh.each { |k, v| send("#{k}=", v) }
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.build_new(options = {})
|
14
|
-
BlogPost.new({:id => 1, :title => "Hello!", :body => "This is my body", :created_at => 1.day.ago, :updated_at => Time.now}.merge(options))
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
class BlogComment < ActiveRecord::Base
|
20
|
-
|
21
|
-
attr_accessor :blog_id
|
22
|
-
attr_accessor :body
|
23
|
-
attr_accessor :created_at
|
24
|
-
attr_accessor :updated_at
|
25
|
-
attr_accessor :id
|
26
|
-
|
27
|
-
def initialize(hsh = {})
|
28
|
-
hsh.each { |k, v| send("#{k}=", v) }
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.build_new(options = {})
|
32
|
-
BlogComment.new({:id => 1, :blog_id => 1, :body => "This is my body", :created_at => 1.day.ago, :updated_at => Time.now}.merge(options))
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
class BlogUser < ActiveRecord::Base
|
38
|
-
|
39
|
-
use_presenter :special_foo
|
40
|
-
|
41
|
-
attr_accessor :username
|
42
|
-
attr_accessor :email
|
43
|
-
attr_accessor :created_at
|
44
|
-
attr_accessor :updated_at
|
45
|
-
attr_accessor :id
|
46
|
-
|
47
|
-
def initialize(hsh = {})
|
48
|
-
hsh.each { |k, v| send("#{k}=", v) }
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.build_new(options = {})
|
52
|
-
BlogUser.new({:id => 1, :username => "markbates", :email => "foo@foo.com", :created_at => 1.day.ago, :updated_at => Time.now}.merge(options))
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
class Poro
|
58
|
-
include ActivePresenter::Presentable
|
59
|
-
end
|
data/test/presenters.rb
DELETED
data/test/proxy_test.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
ENV["RAILS_ENV"] = "test"
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
|
4
|
-
require File.expand_path(File.dirname(__FILE__) + "/../init")
|
5
|
-
require File.expand_path(File.dirname(__FILE__) + "/models")
|
6
|
-
require File.expand_path(File.dirname(__FILE__) + "/presenters")
|
7
|
-
|
8
|
-
class ProxyTest < Test::Unit::TestCase
|
9
|
-
|
10
|
-
def test_empty_constructor
|
11
|
-
p = ActivePresenter::Proxy.new
|
12
|
-
puts "p = #{p.inspect}"
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_hash_constructor
|
16
|
-
p = ActivePresenter::Proxy.new(:foo => :bar)
|
17
|
-
assert p.methods.include?("foo")
|
18
|
-
assert p.methods.include?("foo=")
|
19
|
-
assert_equal :bar, p.foo
|
20
|
-
p.foo = :foo_bar
|
21
|
-
assert_equal :foo_bar, p.foo
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_array_constructor
|
25
|
-
@hello = "Hello There World!"
|
26
|
-
p = ActivePresenter::Proxy.new([:mark, :bates, @hello])
|
27
|
-
assert !p.methods.include?("mark")
|
28
|
-
assert !p.methods.include?("bates")
|
29
|
-
assert !p.methods.include?("hello")
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_methods_genned
|
33
|
-
p = ActivePresenter::Proxy.new
|
34
|
-
assert !p.methods.include?("foo_bar")
|
35
|
-
assert !p.methods.include?("foo_bar=")
|
36
|
-
p.foo_bar = :bar
|
37
|
-
assert_equal :bar, p.foo_bar
|
38
|
-
assert p.methods.include?("foo_bar")
|
39
|
-
assert p.methods.include?("foo_bar=")
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_block
|
43
|
-
p = ActivePresenter::Proxy.new(:cool => :mark)
|
44
|
-
assert_equal :mark, p.cool
|
45
|
-
x = p.cool do |v|
|
46
|
-
assert_equal :mark, v
|
47
|
-
assert_equal 2, 1 + 1
|
48
|
-
v = "mark is cool"
|
49
|
-
assert_equal "mark is cool", v
|
50
|
-
end
|
51
|
-
assert_equal :mark, x
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_define_method
|
55
|
-
p = ActivePresenter::Proxy.new
|
56
|
-
assert !p.methods.include?("my_crazy_method")
|
57
|
-
p.create_method("my_crazy_method") do |k, v|
|
58
|
-
return [1, 2, k, v]
|
59
|
-
end
|
60
|
-
assert p.methods.include?("my_crazy_method")
|
61
|
-
assert_equal [1,2,3,4], p.my_crazy_method(3,4)
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_block_constructor
|
65
|
-
p = ActivePresenter::Proxy.new(:partner => :mark) do |p|
|
66
|
-
assert_equal :mark, p.partner
|
67
|
-
p.baby = :dylan
|
68
|
-
assert_equal p.baby, :dylan
|
69
|
-
end
|
70
|
-
assert_equal :mark, p.partner
|
71
|
-
assert_equal p.baby, :dylan
|
72
|
-
end
|
73
|
-
|
74
|
-
|
75
|
-
end
|