cells 3.8.6 → 3.8.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.textile CHANGED
@@ -1,3 +1,7 @@
1
+ h2. 3.8.7
2
+
3
+ * Cells runs with Rails 4.
4
+
1
5
  h2. 3.8.6
2
6
 
3
7
  * @cell/base@ can now be required without trouble.
data/Gemfile CHANGED
@@ -2,4 +2,4 @@ source :gemcutter
2
2
 
3
3
  gemspec
4
4
 
5
- #gem "rails" , :path => "/home/nick/projects/rayls"
5
+ #gem "rails" , :path => "../rayls"
data/README.rdoc CHANGED
@@ -18,7 +18,7 @@ And the best: You can have as many cells in your page as you need!
18
18
 
19
19
  It's a gem!
20
20
 
21
- Rails 3.x:
21
+ Rails >= 3.0:
22
22
 
23
23
  gem install cells
24
24
 
@@ -235,7 +235,7 @@ Your views can now use the gem's helpers.
235
235
  <%= f.button :submit %>
236
236
  <% end %>
237
237
 
238
- Note that this currently "only" works with Rails 3.2.
238
+ Note that this currently "only" works with Rails 3.2-4.0.
239
239
 
240
240
  == Cells is Rails::Engine aware!
241
241
 
data/cells.gemspec CHANGED
@@ -19,11 +19,10 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency "actionpack", "~> 3.0"
23
- s.add_dependency "railties", "~> 3.0"
22
+ s.add_dependency "actionpack", ">= 3.0"
23
+ s.add_dependency "railties", ">= 3.0"
24
24
 
25
25
  s.add_development_dependency "rake"
26
- s.add_development_dependency "shoulda"
27
26
  s.add_development_dependency "haml"
28
27
  s.add_development_dependency "slim"
29
28
  s.add_development_dependency "simple_form"
data/lib/cell/base.rb CHANGED
@@ -5,15 +5,19 @@ require 'cell/rendering'
5
5
 
6
6
  module Cell
7
7
  def self.rails3_0?
8
- ::ActionPack::VERSION::MINOR == 0
8
+ ::ActionPack::VERSION::MAJOR == 3 and ::ActionPack::VERSION::MINOR == 0
9
9
  end
10
10
 
11
11
  def self.rails3_1_or_more?
12
- ::ActionPack::VERSION::MINOR >= 1
12
+ ::ActionPack::VERSION::MAJOR == 3 and ::ActionPack::VERSION::MINOR >= 1
13
13
  end
14
14
 
15
15
  def self.rails3_2_or_more? # FIXME: move to tests.
16
- ::ActionPack::VERSION::MINOR >= 2
16
+ ::ActionPack::VERSION::MAJOR == 3 and ::ActionPack::VERSION::MINOR >= 2
17
+ end
18
+
19
+ def self.rails4_0_or_more? # FIXME: move to tests.
20
+ ::ActionPack::VERSION::MAJOR == 4
17
21
  end
18
22
 
19
23
 
@@ -27,6 +31,7 @@ module Cell
27
31
 
28
32
  require 'cell/rails3_0_strategy' if Cell.rails3_0?
29
33
  require 'cell/rails3_1_strategy' if Cell.rails3_1_or_more?
34
+ require 'cell/rails4_0_strategy' if Cell.rails4_0_or_more?
30
35
  include VersionStrategy
31
36
  include Rendering
32
37
  include Caching
data/lib/cell/rails.rb CHANGED
@@ -29,6 +29,7 @@ module Cell
29
29
 
30
30
 
31
31
  attr_reader :parent_controller
32
+ alias_method :controller, :parent_controller
32
33
 
33
34
  def initialize(parent_controller)
34
35
  super
@@ -65,14 +65,16 @@ module Cell
65
65
  end
66
66
 
67
67
 
68
- module Cells::Engines
69
- module VersionStrategy
70
- def registered_engines
71
- ::Rails::Application.railties.engines
72
- end
73
-
74
- def existent_directories_for(path)
75
- path.to_a.select { |d| File.directory?(d) }
68
+ module Cells
69
+ module Engines
70
+ module VersionStrategy
71
+ def registered_engines
72
+ ::Rails::Application.railties.engines
73
+ end
74
+
75
+ def existent_directories_for(path)
76
+ path.to_a.select { |d| File.directory?(d) }
77
+ end
76
78
  end
77
79
  end
78
80
  end
@@ -23,14 +23,16 @@ module Cell
23
23
  end
24
24
 
25
25
 
26
- module Cells::Engines
27
- module VersionStrategy
28
- def registered_engines
29
- ::Rails::Application::Railties.engines
30
- end
31
-
32
- def existent_directories_for(path)
33
- path.existent_directories
26
+ module Cells
27
+ module Engines
28
+ module VersionStrategy
29
+ def registered_engines
30
+ ::Rails::Application::Railties.engines
31
+ end
32
+
33
+ def existent_directories_for(path)
34
+ path.existent_directories
35
+ end
34
36
  end
35
37
  end
36
38
  end
@@ -78,7 +78,7 @@ module Cell
78
78
  Hash[(after - before).collect do |var|
79
79
  next if var =~ /^@_/
80
80
  [var[1, var.length].to_sym, cell.instance_variable_get(var)]
81
- end]
81
+ end.compact]
82
82
  end
83
83
  end
84
84
 
data/lib/cells/engines.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'rails/application/railties'
2
-
3
1
  module Cells
4
2
  # Now <tt>Rails::Engine</tt>s can contribute to Cells view paths.
5
3
  # By default, any 'app/cells' found inside any Engine is automatically included into Cells view paths.
data/lib/cells/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cells
2
- VERSION = '3.8.6'
2
+ VERSION = '3.8.7'
3
3
  end
@@ -6,110 +6,108 @@ class CellGeneratorTest < Rails::Generators::TestCase
6
6
  setup :prepare_destination
7
7
  tests ::Rails::Generators::CellGenerator
8
8
 
9
- context "CellGenerator" do
10
- should "create the standard assets" do
11
- run_generator %w(Blog post latest)
12
-
13
- assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
14
- assert_file "app/cells/blog_cell.rb", /def post/
15
- assert_file "app/cells/blog_cell.rb", /def latest/
16
- assert_file "app/cells/blog/post.html.erb", %r(app/cells/blog/post\.html\.erb)
17
- assert_file "app/cells/blog/post.html.erb", %r(<p>)
18
- assert_file "app/cells/blog/latest.html.erb", %r(app/cells/blog/latest\.html\.erb)
19
-
20
-
21
- assert_no_file "app/cells/blog/post.html.haml"
22
- assert_no_file "app/cells/blog/post.html.haml"
23
- assert_no_file "app/cells/blog/latest.html.haml"
24
-
25
- assert_no_file "app/cells/blog/post.html.slim"
26
- assert_no_file "app/cells/blog/post.html.slim"
27
- assert_no_file "app/cells/blog/latest.html.slim"
28
- end
29
-
30
- should "create cell that inherits from custom cell class if specified" do
31
- run_generator %w(Blog --base-cell-class=ApplicationCell)
32
- assert_file "app/cells/blog_cell.rb", /class BlogCell < ApplicationCell/
33
- end
34
-
35
- should "work with namespaces" do
36
- run_generator %w(Blog::Post latest)
37
-
38
- assert_file "app/cells/blog/post_cell.rb", /class Blog::PostCell < Cell::Rails/
39
- assert_file "app/cells/blog/post_cell.rb", /def latest/
40
- assert_file "app/cells/blog/post/latest.html.erb", %r(app/cells/blog/post/latest\.html\.erb)
41
- end
42
-
43
- should "work with namespaces and haml" do
44
- run_generator %w(Blog::Post latest -e haml)
45
-
46
- assert_file "app/cells/blog/post_cell.rb", /class Blog::PostCell < Cell::Rails/
47
- assert_file "app/cells/blog/post/latest.html.haml", %r(app/cells/blog/post/latest\.html\.haml)
48
- end
49
-
50
- should "work with namespaces and slim" do
51
- run_generator %w(Blog::Post latest -e slim)
52
-
53
- assert_file "app/cells/blog/post_cell.rb", /class Blog::PostCell < Cell::Rails/
54
- assert_file "app/cells/blog/post/latest.html.slim", %r(app/cells/blog/post/latest\.html\.slim)
55
- end
56
-
57
- should "create slim assets with -e slim" do
58
- run_generator %w(Blog post latest -e slim)
59
-
60
- assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
61
- assert_file "app/cells/blog_cell.rb", /def post/
62
- assert_file "app/cells/blog_cell.rb", /def latest/
63
- assert_file "app/cells/blog/post.html.slim", %r(app/cells/blog/post\.html\.slim)
64
- assert_file "app/cells/blog/post.html.slim", %r(p)
65
- assert_file "app/cells/blog/latest.html.slim", %r(app/cells/blog/latest\.html\.slim)
66
-
67
-
68
- assert_no_file "app/cells/blog/post.html.erb"
69
- assert_no_file "app/cells/blog/post.html.erb"
70
- assert_no_file "app/cells/blog/latest.html.erb"
71
-
72
- assert_no_file "app/cells/blog/post.html.haml"
73
- assert_no_file "app/cells/blog/post.html.haml"
74
- assert_no_file "app/cells/blog/latest.html.haml"
75
- end
76
-
77
- should "create haml assets with -e haml" do
78
- run_generator %w(Blog post latest -e haml)
79
-
80
- assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
81
- assert_file "app/cells/blog_cell.rb", /def post/
82
- assert_file "app/cells/blog_cell.rb", /def latest/
83
- assert_file "app/cells/blog/post.html.haml", %r(app/cells/blog/post\.html\.haml)
84
- assert_file "app/cells/blog/post.html.haml", %r(%p)
85
- assert_file "app/cells/blog/latest.html.haml", %r(app/cells/blog/latest\.html\.haml)
86
-
87
-
88
- assert_no_file "app/cells/blog/post.html.erb"
89
- assert_no_file "app/cells/blog/post.html.erb"
90
- assert_no_file "app/cells/blog/latest.html.erb"
91
-
92
- assert_no_file "app/cells/blog/post.html.slim"
93
- assert_no_file "app/cells/blog/post.html.slim"
94
- assert_no_file "app/cells/blog/latest.html.slim"
95
- end
96
-
97
- should "create test_unit assets with -t test_unit" do
98
- run_generator %w(Blog post latest -t test_unit)
99
-
100
- assert_file "test/cells/blog_cell_test.rb"
101
- end
102
-
103
- should "work with namespace and test_unit" do
104
- run_generator %w(Blog::Post latest -t test_unit)
105
-
106
- assert_file "test/cells/blog/post_cell_test.rb", /class Blog::PostCellTest < Cell::TestCase/
107
- end
108
-
109
- should "create test_unit assets with -t rspec" do
110
- run_generator %w(Blog post latest -t rspec)
9
+ test "create the standard assets" do
10
+ run_generator %w(Blog post latest)
111
11
 
112
- assert_no_file "test/cells/blog_cell_test.rb"
113
- end
12
+ assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
13
+ assert_file "app/cells/blog_cell.rb", /def post/
14
+ assert_file "app/cells/blog_cell.rb", /def latest/
15
+ assert_file "app/cells/blog/post.html.erb", %r(app/cells/blog/post\.html\.erb)
16
+ assert_file "app/cells/blog/post.html.erb", %r(<p>)
17
+ assert_file "app/cells/blog/latest.html.erb", %r(app/cells/blog/latest\.html\.erb)
18
+
19
+
20
+ assert_no_file "app/cells/blog/post.html.haml"
21
+ assert_no_file "app/cells/blog/post.html.haml"
22
+ assert_no_file "app/cells/blog/latest.html.haml"
23
+
24
+ assert_no_file "app/cells/blog/post.html.slim"
25
+ assert_no_file "app/cells/blog/post.html.slim"
26
+ assert_no_file "app/cells/blog/latest.html.slim"
27
+ end
28
+
29
+ test "create cell that inherits from custom cell class if specified" do
30
+ run_generator %w(Blog --base-cell-class=ApplicationCell)
31
+ assert_file "app/cells/blog_cell.rb", /class BlogCell < ApplicationCell/
32
+ end
33
+
34
+ test "work with namespaces" do
35
+ run_generator %w(Blog::Post latest)
36
+
37
+ assert_file "app/cells/blog/post_cell.rb", /class Blog::PostCell < Cell::Rails/
38
+ assert_file "app/cells/blog/post_cell.rb", /def latest/
39
+ assert_file "app/cells/blog/post/latest.html.erb", %r(app/cells/blog/post/latest\.html\.erb)
40
+ end
41
+
42
+ test "work with namespaces and haml" do
43
+ run_generator %w(Blog::Post latest -e haml)
44
+
45
+ assert_file "app/cells/blog/post_cell.rb", /class Blog::PostCell < Cell::Rails/
46
+ assert_file "app/cells/blog/post/latest.html.haml", %r(app/cells/blog/post/latest\.html\.haml)
47
+ end
48
+
49
+ test "work with namespaces and slim" do
50
+ run_generator %w(Blog::Post latest -e slim)
51
+
52
+ assert_file "app/cells/blog/post_cell.rb", /class Blog::PostCell < Cell::Rails/
53
+ assert_file "app/cells/blog/post/latest.html.slim", %r(app/cells/blog/post/latest\.html\.slim)
54
+ end
55
+
56
+ test "create slim assets with -e slim" do
57
+ run_generator %w(Blog post latest -e slim)
58
+
59
+ assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
60
+ assert_file "app/cells/blog_cell.rb", /def post/
61
+ assert_file "app/cells/blog_cell.rb", /def latest/
62
+ assert_file "app/cells/blog/post.html.slim", %r(app/cells/blog/post\.html\.slim)
63
+ assert_file "app/cells/blog/post.html.slim", %r(p)
64
+ assert_file "app/cells/blog/latest.html.slim", %r(app/cells/blog/latest\.html\.slim)
65
+
66
+
67
+ assert_no_file "app/cells/blog/post.html.erb"
68
+ assert_no_file "app/cells/blog/post.html.erb"
69
+ assert_no_file "app/cells/blog/latest.html.erb"
70
+
71
+ assert_no_file "app/cells/blog/post.html.haml"
72
+ assert_no_file "app/cells/blog/post.html.haml"
73
+ assert_no_file "app/cells/blog/latest.html.haml"
74
+ end
75
+
76
+ test "create haml assets with -e haml" do
77
+ run_generator %w(Blog post latest -e haml)
78
+
79
+ assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
80
+ assert_file "app/cells/blog_cell.rb", /def post/
81
+ assert_file "app/cells/blog_cell.rb", /def latest/
82
+ assert_file "app/cells/blog/post.html.haml", %r(app/cells/blog/post\.html\.haml)
83
+ assert_file "app/cells/blog/post.html.haml", %r(%p)
84
+ assert_file "app/cells/blog/latest.html.haml", %r(app/cells/blog/latest\.html\.haml)
85
+
86
+
87
+ assert_no_file "app/cells/blog/post.html.erb"
88
+ assert_no_file "app/cells/blog/post.html.erb"
89
+ assert_no_file "app/cells/blog/latest.html.erb"
90
+
91
+ assert_no_file "app/cells/blog/post.html.slim"
92
+ assert_no_file "app/cells/blog/post.html.slim"
93
+ assert_no_file "app/cells/blog/latest.html.slim"
94
+ end
95
+
96
+ test "create test_unit assets with -t test_unit" do
97
+ run_generator %w(Blog post latest -t test_unit)
98
+
99
+ assert_file "test/cells/blog_cell_test.rb"
100
+ end
101
+
102
+ test "work with namespace and test_unit" do
103
+ run_generator %w(Blog::Post latest -t test_unit)
104
+
105
+ assert_file "test/cells/blog/post_cell_test.rb", /class Blog::PostCellTest < Cell::TestCase/
106
+ end
107
+
108
+ test "create test_unit assets with -t rspec" do
109
+ run_generator %w(Blog post latest -t rspec)
110
+
111
+ assert_no_file "test/cells/blog_cell_test.rb"
114
112
  end
115
113
  end
@@ -42,16 +42,16 @@ class CellBaseTest < MiniTest::Spec
42
42
  end
43
43
 
44
44
 
45
- class CellModuleTest < ActiveSupport::TestCase
45
+ class CellModuleTest < MiniTest::Spec
46
46
  include Cell::TestCase::TestMethods
47
- context "Cell::Rails" do
47
+ describe "Cell::Rails" do
48
48
  # FUNCTIONAL:
49
- context "render_cell_for" do
50
- should "render the actual cell" do
49
+ describe "render_cell_for" do
50
+ it "render the actual cell" do
51
51
  assert_equal "Doo", Cell::Rails.render_cell_for(:bassist, :play, @controller)
52
52
  end
53
53
 
54
- should "accept a block, passing the cell instance" do
54
+ it "accept a block, passing the cell instance" do
55
55
  flag = false
56
56
  html = Cell::Rails.render_cell_for(:bassist, :play, @controller) do |cell|
57
57
  assert_equal BassistCell, cell.class
@@ -63,8 +63,8 @@ class CellModuleTest < ActiveSupport::TestCase
63
63
  end
64
64
  end
65
65
 
66
- context "create_cell_for" do
67
- should "call the cell's builders, eventually returning a different class" do
66
+ describe "create_cell_for" do
67
+ it "call the cell's builders, eventually returning a different class" do
68
68
  class DrummerCell < BassistCell
69
69
  build do
70
70
  BassistCell
@@ -75,8 +75,8 @@ class CellModuleTest < ActiveSupport::TestCase
75
75
  end
76
76
  end
77
77
 
78
- context "#create_cell_for with #build" do
79
- setup do
78
+ describe "#create_cell_for with #build" do
79
+ before do
80
80
  @controller.class_eval do
81
81
  attr_accessor :bassist
82
82
  end
@@ -86,7 +86,7 @@ class CellModuleTest < ActiveSupport::TestCase
86
86
  end
87
87
  end
88
88
 
89
- teardown do
89
+ after do
90
90
  MusicianCell.class_eval do
91
91
  @builders = false
92
92
  end
@@ -95,24 +95,24 @@ class CellModuleTest < ActiveSupport::TestCase
95
95
  end
96
96
  end
97
97
 
98
- should "execute the block in controller context" do
98
+ it "execute the block in controller describe" do
99
99
  @controller.bassist = true
100
100
  assert_is_a BassistCell, Cell::Rails.create_cell_for(:musician, @controller)
101
101
  end
102
102
 
103
- should "limit the builder to the receiving class" do
103
+ it "limit the builder to the receiving class" do
104
104
  assert_is_a PianistCell, Cell::Rails.create_cell_for(:pianist, @controller) # don't inherit anything.
105
105
  @controller.bassist = true
106
106
  assert_is_a BassistCell, Cell::Rails.create_cell_for(:musician, @controller)
107
107
  end
108
108
 
109
- should "chain build blocks and execute them by ORing them in the same order" do
109
+ it "chain build blocks and execute them by ORing them in the same order" do
110
110
  MusicianCell.build do
111
111
  PianistCell unless bassist
112
112
  end
113
113
 
114
114
  MusicianCell.build do
115
- UnknownCell # should never be executed.
115
+ UnknownCell # it never be executed.
116
116
  end
117
117
 
118
118
  assert_is_a PianistCell, Cell::Rails.create_cell_for(:musician, @controller) # bassist is false.
@@ -120,15 +120,15 @@ class CellModuleTest < ActiveSupport::TestCase
120
120
  assert_is_a BassistCell, Cell::Rails.create_cell_for(:musician, @controller)
121
121
  end
122
122
 
123
- should "use the original cell if no builder matches" do
123
+ it "use the original cell if no builder matches" do
124
124
  assert_is_a MusicianCell, Cell::Rails.create_cell_for(:musician, @controller) # bassist is false.
125
125
  end
126
126
 
127
- should "stop at the first builder returning a valid cell" do
127
+ it "stop at the first builder returning a valid cell" do
128
128
 
129
129
  end
130
130
 
131
- should "pass options to the block" do
131
+ it "pass options to the block" do
132
132
  BassistCell.build do |opts|
133
133
  SingerCell if opts[:sing_the_song]
134
134
  end
@@ -136,29 +136,29 @@ class CellModuleTest < ActiveSupport::TestCase
136
136
  assert_kind_of SingerCell, Cell::Rails.create_cell_for(:bassist, @controller, {:sing_the_song => true})
137
137
  end
138
138
 
139
- should "create the original target class if no block matches" do
139
+ it "create the original target class if no block matches" do
140
140
  assert_kind_of PianistCell, Cell::Rails.create_cell_for(:pianist, @controller)
141
141
  end
142
142
 
143
- should "builders should return an empty array per default" do
143
+ it "builders it return an empty array per default" do
144
144
  assert_equal [], PianistCell.send(:builders)
145
145
  end
146
146
  end
147
147
 
148
- should "provide class_from_cell_name" do
148
+ it "provide class_from_cell_name" do
149
149
  assert_equal BassistCell, ::Cell::Rails.class_from_cell_name('bassist')
150
150
  end
151
151
 
152
152
  if Cell.rails3_0?
153
- should "provide possible_paths_for_state" do
153
+ it "provide possible_paths_for_state" do
154
154
  assert_equal ["bad_guitarist/play", "bassist/play"], cell(:bad_guitarist).send(:possible_paths_for_state, :play)
155
155
  end
156
156
 
157
- should "provide Cell.cell_name" do
157
+ it "provide Cell.cell_name" do
158
158
  assert_equal 'bassist', cell(:bassist).class.cell_name
159
159
  end
160
160
 
161
- should "provide cell_name for modules, too" do
161
+ it "provide cell_name for modules, too" do
162
162
  class SingerCell < Cell::Rails
163
163
  end
164
164
 
@@ -167,16 +167,20 @@ class CellModuleTest < ActiveSupport::TestCase
167
167
  end
168
168
  end
169
169
 
170
- should "respond to #rails3_1_or_more?" do
171
- if Rails::VERSION::MINOR == 0
172
- assert ! Cell.rails3_1_or_more?
173
- assert Cell.rails3_0?
174
- elsif Rails::VERSION::MINOR == 1
175
- assert Cell.rails3_1_or_more?
176
- assert ! Cell.rails3_0?
177
- elsif Rails::VERSION::MINOR == 2
178
- assert Cell.rails3_1_or_more?
179
- assert ! Cell.rails3_0?
170
+ it "respond to #rails3_1_or_more?" do
171
+ if Rails::VERSION::MAJOR == 3
172
+ if Rails::VERSION::MINOR == 0
173
+ assert ! Cell.rails3_1_or_more?
174
+ assert Cell.rails3_0?
175
+ elsif Rails::VERSION::MINOR == 1
176
+ assert Cell.rails3_1_or_more?
177
+ assert ! Cell.rails3_0?
178
+ elsif Rails::VERSION::MINOR == 2
179
+ assert Cell.rails3_1_or_more?
180
+ assert ! Cell.rails3_0?
181
+ end
182
+ elsif Rails::VERSION::MAJOR == 4
183
+ assert Cell.rails4_0_or_more?
180
184
  end
181
185
  end
182
186
  end