proffer 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -0
- data/lib/proffer.rb +23 -3
- data/spec/proffer_integration_spec.rb +31 -0
- data/spec/proffer_spec.rb +21 -0
- data/spec/spec_helper.rb +3 -0
- metadata +6 -8
data/README.md
CHANGED
@@ -51,6 +51,23 @@ Any proffered values will then be available to your views by their key:
|
|
51
51
|
<% end %>
|
52
52
|
```
|
53
53
|
|
54
|
+
You can test your use of Proffer by inspecting the `proffered` method on your
|
55
|
+
controllers instead of using `assigns` like so:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
describe FooController do
|
59
|
+
describe "GET index" do
|
60
|
+
it "only proffers the title" do
|
61
|
+
get :index
|
62
|
+
controller.proffered.should == { :title => "Title" }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
Note that if you set `@title` in a Proffer-enabled action, `assigns(:title)`
|
69
|
+
will be `nil`.
|
70
|
+
|
54
71
|
Compatibility
|
55
72
|
-------------
|
56
73
|
|
data/lib/proffer.rb
CHANGED
@@ -16,6 +16,11 @@
|
|
16
16
|
# end
|
17
17
|
module Proffer
|
18
18
|
|
19
|
+
# Internal: Ensure that methods are not defined as actions.
|
20
|
+
def self.included(base)
|
21
|
+
base.hide_action :proffer, :proffered
|
22
|
+
end
|
23
|
+
|
19
24
|
# Public: Make the given values available to the view as local variables.
|
20
25
|
#
|
21
26
|
# variables - The Hash of values keyed by the local variable name to be used
|
@@ -28,17 +33,32 @@ module Proffer
|
|
28
33
|
#
|
29
34
|
# Returns nothing.
|
30
35
|
def proffer(variables)
|
36
|
+
proffered.merge!(variables)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Public: All proffered values and their given keys.
|
40
|
+
#
|
41
|
+
# Examples
|
42
|
+
#
|
43
|
+
# proffered
|
44
|
+
# # => {}
|
45
|
+
#
|
46
|
+
# proffer :foo => "bar"
|
47
|
+
# proffered
|
48
|
+
# # => { :foo => "bar" }
|
49
|
+
#
|
50
|
+
# Returns a Hash of proffered keys and values.
|
51
|
+
def proffered
|
31
52
|
@_proffered_variables ||= {}
|
32
|
-
@_proffered_variables.merge!(variables)
|
33
53
|
end
|
34
54
|
|
35
55
|
# Internal: Override Action Controller's render method to convert proffered
|
36
56
|
# variables to locals.
|
37
57
|
def render(*args, &blk)
|
38
|
-
|
58
|
+
unless proffered.empty?
|
39
59
|
options = args.extract_options!
|
40
60
|
options[:locals] ||= {}
|
41
|
-
options[:locals] =
|
61
|
+
options[:locals] = proffered.merge(options[:locals])
|
42
62
|
args << options
|
43
63
|
end
|
44
64
|
|
@@ -11,15 +11,33 @@ class ProfferTestController < ApplicationController
|
|
11
11
|
@foo = "Not passed through"
|
12
12
|
proffer :my_nice_variable => "Woooo"
|
13
13
|
end
|
14
|
+
|
15
|
+
def inline
|
16
|
+
proffer :foo => "bar"
|
17
|
+
render :inline => "My name is <%= foo %>"
|
18
|
+
end
|
14
19
|
end
|
15
20
|
|
16
21
|
TestApplication.routes.draw do
|
17
22
|
match "/foo" => "proffer_test#index"
|
23
|
+
match "/inline" => "proffer_test#inline"
|
18
24
|
end
|
19
25
|
|
20
26
|
describe ProfferTestController, :type => :controller do
|
21
27
|
render_views
|
22
28
|
|
29
|
+
describe "#proffer" do
|
30
|
+
it "is not an available action" do
|
31
|
+
controller.available_action?("proffer").should be_false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#proffered" do
|
36
|
+
it "is not an available action" do
|
37
|
+
controller.available_action?("proffered").should be_false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
23
41
|
describe "#index" do
|
24
42
|
describe "as html" do
|
25
43
|
it "won't pass instance variables to the view by default" do
|
@@ -27,6 +45,11 @@ describe ProfferTestController, :type => :controller do
|
|
27
45
|
response.body.should_not =~ /Not passed through/
|
28
46
|
end
|
29
47
|
|
48
|
+
it "doesn't set assigns" do
|
49
|
+
get :index
|
50
|
+
assigns(:foo).should be_nil
|
51
|
+
end
|
52
|
+
|
30
53
|
it "will pass proffered variables to the view" do
|
31
54
|
get :index
|
32
55
|
response.body.should =~ /Woooo/
|
@@ -45,4 +68,12 @@ describe ProfferTestController, :type => :controller do
|
|
45
68
|
end
|
46
69
|
end
|
47
70
|
end
|
71
|
+
|
72
|
+
describe "#inline" do
|
73
|
+
it "works with inline rendering" do
|
74
|
+
get :inline
|
75
|
+
response.body.should =~ /My name is bar/
|
76
|
+
end
|
77
|
+
end
|
48
78
|
end
|
79
|
+
|
data/spec/proffer_spec.rb
CHANGED
@@ -22,6 +22,11 @@ class FakeController < BaseController
|
|
22
22
|
proffer :baz => "quux"
|
23
23
|
render :multiple_proffer
|
24
24
|
end
|
25
|
+
|
26
|
+
def render_with_no_args
|
27
|
+
proffer :foo => "bar"
|
28
|
+
render
|
29
|
+
end
|
25
30
|
end
|
26
31
|
|
27
32
|
describe Proffer do
|
@@ -56,6 +61,22 @@ describe Proffer do
|
|
56
61
|
controller.multiple_proffer
|
57
62
|
controller.args_for_render.should == [:multiple_proffer, { :locals => { :foo => "bar", :baz => "quux" } }]
|
58
63
|
end
|
64
|
+
|
65
|
+
it "supports implicit rendering with no arguments" do
|
66
|
+
controller.render_with_no_args
|
67
|
+
controller.args_for_render.should == [{ :locals => { :foo => "bar" } }]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#proffered" do
|
72
|
+
it "is an empty hash by default" do
|
73
|
+
controller.proffered.should == {}
|
74
|
+
end
|
75
|
+
|
76
|
+
it "returns all proffered variables" do
|
77
|
+
controller.multiple_proffer
|
78
|
+
controller.proffered.should == { :foo => "bar", :baz => "quux" }
|
79
|
+
end
|
59
80
|
end
|
60
81
|
end
|
61
82
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proffer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 55
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 10
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.10.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- James Hunt
|
@@ -16,8 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-
|
20
|
-
default_executable:
|
19
|
+
date: 2012-04-01 00:00:00 Z
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
23
22
|
name: rspec-rails
|
@@ -80,8 +79,7 @@ files:
|
|
80
79
|
- spec/proffer_integration_spec.rb
|
81
80
|
- spec/fixtures/proffer_test/index.html.erb
|
82
81
|
- spec/fixtures/proffer_test/index.xml.builder
|
83
|
-
|
84
|
-
homepage: http://github.com/hudge/proffer
|
82
|
+
homepage: https://github.com/hudge/proffer
|
85
83
|
licenses: []
|
86
84
|
|
87
85
|
post_install_message:
|
@@ -110,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
108
|
requirements: []
|
111
109
|
|
112
110
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.
|
111
|
+
rubygems_version: 1.8.21
|
114
112
|
signing_key:
|
115
113
|
specification_version: 3
|
116
114
|
summary: An Action Controller module to hide instance variables from views by default.
|