cells 3.6.6 → 3.6.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ pkg
5
5
  Gemfile.lock
6
6
  test/dummy/log/*.log
7
7
  test/dummy/tmp/
8
+ /.rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm: 1.9.2
2
+ notifications:
3
+ irc: "irc.freenode.org#cells"
data/CHANGES.textile CHANGED
@@ -1,3 +1,8 @@
1
+ h2. 3.6.7
2
+
3
+ h3. Changes
4
+ * Added @view_assigns@ to TestCase.
5
+
1
6
  h2. 3.6.6
2
7
 
3
8
  h3. Changes
data/README.rdoc CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  <em>View Components for Rails.</em>
4
4
 
5
+ {<img src="https://secure.travis-ci.org/apotonick/cells.png" />}[http://travis-ci.org/apotonick/cells]
6
+
5
7
  == Overview
6
8
 
7
9
  Say you're writing a Rails online shop - the shopping cart is reappearing again and again in every view. You're thinking about a clean solution for that part. A mixture of controller code, before-filters, partials and helpers?
data/lib/cell.rb CHANGED
@@ -14,8 +14,8 @@ module Cell
14
14
  end
15
15
 
16
16
  def render_cell_for(controller, name, state, *args)
17
- cell = create_cell_for(controller, name, *args) # DISCUSS: we always save options.
18
- yield cell if block_given?
17
+ cell = create_cell_for(controller, name, *args) # DISCUSS: pass args here?
18
+ yield cell if block_given? # DISCUSS: call block before or after render?
19
19
 
20
20
  cell.render_state_with_args(state, *args)
21
21
  end
@@ -58,8 +58,8 @@ module Cell
58
58
  super(HTML::Document.new(last_invoke).root, *args, &block)
59
59
  end
60
60
  end
61
-
62
- module TestMethods
61
+
62
+ module CommonTestMethods
63
63
  def setup
64
64
  @controller = Class.new(ActionController::Base).new
65
65
  @request = ::ActionController::TestRequest.new
@@ -68,15 +68,40 @@ module Cell
68
68
  @controller.response = @response
69
69
  @controller.params = {}
70
70
  end
71
+
72
+ # Runs the block while computing the instance variables diff from before and after.
73
+ def extract_state_ivars_for(cell)
74
+ before = cell.instance_variables
75
+ yield
76
+ after = cell.instance_variables
77
+
78
+ Hash[(after - before).collect do |var|
79
+ next if var =~ /^@_/
80
+ [var[1, var.length].to_sym, cell.instance_variable_get(var)]
81
+ end]
82
+ end
83
+ end
84
+
71
85
 
86
+ module TestMethods
87
+ include CommonTestMethods
88
+
89
+ attr_reader :last_invoke, :subject_cell, :view_assigns
90
+
72
91
  # Use this for functional tests of your application cells.
73
92
  #
74
93
  # Example:
75
94
  # should "spit out a h1 title" do
76
95
  # html = render_cell(:news, :latest)
77
- # assert_selekt html, "h1", "The latest and greatest!"
78
- def render_cell(*args)
79
- @controller.render_cell(*args)
96
+ # assert_select html, "h1", "The latest and greatest!"
97
+ def render_cell(name, state, *args)
98
+ # DISCUSS: should we allow passing a block here, just as in controllers?
99
+ @subject_cell = ::Cell::Base.create_cell_for(@controller, name, *args)
100
+ @view_assigns = extract_state_ivars_for(@subject_cell) do
101
+ @last_invoke = @subject_cell.render_state_with_args(state, *args)
102
+ end
103
+
104
+ @last_invoke
80
105
  end
81
106
 
82
107
  # Builds an instance of <tt>name</tt>Cell for unit testing.
@@ -89,8 +114,8 @@ module Cell
89
114
  cell.instance_eval &block if block_given?
90
115
  cell
91
116
  end
92
-
93
- # Execute the passed +block+ in a real view context of +cell_class+.
117
+
118
+ # Execute the passed +block+ in a real view context of +cell_class+.
94
119
  # Usually you'd test helpers here.
95
120
  #
96
121
  # Example:
@@ -101,7 +126,7 @@ module Cell
101
126
  setup_test_states_in(subject) # add #in_view to subject cell.
102
127
  subject.render_state(:in_view)
103
128
  end
104
-
129
+
105
130
  protected
106
131
  def setup_test_states_in(cell)
107
132
  cell.instance_eval do
@@ -119,9 +144,7 @@ module Cell
119
144
 
120
145
  extend ActionController::TestCase::Behavior::ClassMethods
121
146
  class_attribute :_controller_class
122
-
123
-
124
- attr_reader :last_invoke
147
+
125
148
 
126
149
  def invoke(state, *args)
127
150
  @last_invoke = self.class.controller_class.new(@controller, *args).render_state_with_args(state, *args)
data/lib/cells/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cells
2
- VERSION = '3.6.6'
2
+ VERSION = '3.6.7'
3
3
  end
@@ -11,7 +11,6 @@ class TestCaseTest < Cell::TestCase
11
11
  end
12
12
  end
13
13
 
14
-
15
14
  should "respond to #render_cell" do
16
15
  assert_equal "Doo", render_cell(:bassist, :play)
17
16
  end
@@ -32,6 +31,31 @@ class TestCaseTest < Cell::TestCase
32
31
  assert_equal({:topic => :peace}, cell(:bassist, :topic => :peace).options)
33
32
  end
34
33
 
34
+ context "#subject_cell" do
35
+ should "return the last rendered cell" do
36
+ render_cell(:bassist, :play)
37
+ assert_kind_of BassistCell, subject_cell
38
+ end
39
+ end
40
+
41
+
42
+ context "#view_assigns" do
43
+ should "be emtpy when nothing was set" do
44
+ render_cell(:bassist, :play)
45
+ assert_equal({}, view_assigns)
46
+ end
47
+
48
+ should "return the instance variables from the last #render_cell" do
49
+ BassistCell.class_eval do
50
+ def sleep
51
+ @duration = "8h"
52
+ end
53
+ end
54
+ render_cell(:bassist, :sleep)
55
+ assert_equal({:duration => "8h"}, view_assigns)
56
+ end
57
+ end
58
+
35
59
  context "in declarative tests" do
36
60
  should "respond to TestCase.tests" do
37
61
  self.class.tests BassistCell
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 3
7
7
  - 6
8
- - 6
9
- version: 3.6.6
8
+ - 7
9
+ version: 3.6.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nick Sutterer
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-09-21 00:00:00 +02:00
17
+ date: 2011-09-28 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -121,6 +121,7 @@ extra_rdoc_files: []
121
121
 
122
122
  files:
123
123
  - .gitignore
124
+ - .travis.yml
124
125
  - CHANGES.textile
125
126
  - Gemfile
126
127
  - README.rdoc