cells 3.3.0 → 3.3.1
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/Rakefile +1 -1
- data/lib/cells/assertions_helper.rb +49 -0
- data/lib/cells/version.rb +2 -2
- data/{generators → rails_generators}/cell/USAGE +0 -0
- data/{generators → rails_generators}/cell/cell_generator.rb +6 -3
- data/{generators → rails_generators}/cell/templates/cell.rb +0 -0
- data/rails_generators/cell/templates/cell_test.rb +13 -0
- data/{generators → rails_generators}/cell/templates/view.html.erb +0 -0
- data/{generators → rails_generators}/cell/templates/view.html.haml +0 -0
- data/{generators → rails_generators}/cells_install/USAGE +0 -0
- data/{generators → rails_generators}/cells_install/cells_install_generator.rb +0 -0
- data/{generators → rails_generators}/cells_install/templates/initializer.rb +0 -0
- data/test/assertions_helper_test.rb +43 -0
- data/test/cell_generator_test.rb +48 -0
- data/test/support/{assertions_helper.rb → internal_assertions_helper.rb} +15 -11
- data/test/test_helper.rb +9 -0
- metadata +26 -22
data/Rakefile
CHANGED
@@ -62,7 +62,7 @@ begin
|
|
62
62
|
spec.authors = ["Nick Sutterer"]
|
63
63
|
spec.email = "apotonick@gmail.com"
|
64
64
|
|
65
|
-
spec.files = FileList["[A-Z]*", File.join(*%w[{
|
65
|
+
spec.files = FileList["[A-Z]*", File.join(*%w[{lib,rails,rails_generators} ** *]).to_s]
|
66
66
|
|
67
67
|
# spec.add_dependency 'activesupport', '>= 2.3.0' # Dependencies and minimum versions?
|
68
68
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'action_controller/test_case'
|
3
|
+
|
4
|
+
module Cells
|
5
|
+
module AssertionsHelper
|
6
|
+
# Sets up a mock controller for usage in render_cell.
|
7
|
+
def setup
|
8
|
+
@controller = Class.new(ActionController::Base).new
|
9
|
+
@request = ::ActionController::TestRequest.new
|
10
|
+
@response = ::ActionController::TestResponse.new
|
11
|
+
@controller.request = @request
|
12
|
+
@controller.response = @response
|
13
|
+
@controller.params = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
# Use this for functional tests of your application cells.
|
17
|
+
#
|
18
|
+
# Example:
|
19
|
+
# should "spit out a h1 title" do
|
20
|
+
# html = render_cell(:news, :latest)
|
21
|
+
# assert_selekt html, "h1", "The latest and greatest!"
|
22
|
+
def render_cell(*args)
|
23
|
+
@controller.render_cell(*args)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Invokes assert_select for the passed <tt>content</tt> string.
|
27
|
+
#
|
28
|
+
# Example:
|
29
|
+
# html = "<h1>The latest and greatest!</h1>"
|
30
|
+
# assert_selekt html, "h1", "The latest and greatest!"
|
31
|
+
#
|
32
|
+
# would be true.
|
33
|
+
def assert_selekt(content, *args)
|
34
|
+
assert_select(HTML::Document.new(content).root, *args)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Builds an instance of <tt>name</tt>Cell for unit testing.
|
38
|
+
# Passes the optional block to <tt>cell.instance_eval</tt>.
|
39
|
+
#
|
40
|
+
# Example:
|
41
|
+
# assert_equal "Banks kill planet!" cell(:news, :topic => :terror).latest_headline
|
42
|
+
def cell(name, opts={}, &block)
|
43
|
+
cell = Cell::Base.create_cell_for(@controller, name, opts)
|
44
|
+
cell.instance_eval &block if block_given?
|
45
|
+
cell
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
data/lib/cells/version.rb
CHANGED
File without changes
|
@@ -17,16 +17,19 @@ class CellGenerator < ControllerGenerator
|
|
17
17
|
# Directories
|
18
18
|
m.directory File.join('app/cells', class_path)
|
19
19
|
m.directory File.join('app/cells', class_path, file_name)
|
20
|
-
|
20
|
+
m.directory File.join('test/cells')
|
21
|
+
|
21
22
|
# Cell
|
22
23
|
m.template 'cell.rb', File.join('app/cells', class_path, "#{file_name}_cell.rb")
|
23
24
|
|
24
25
|
# View template for each action.
|
25
26
|
actions.each do |action|
|
26
27
|
path = File.join('app/cells', class_path, file_name, "#{action}.html.#{template_type}")
|
27
|
-
m.template "view.html.#{template_type}", path,
|
28
|
-
:assigns => { :action => action, :path => path }
|
28
|
+
m.template "view.html.#{template_type}", path, :assigns => { :action => action, :path => path }
|
29
29
|
end
|
30
|
+
|
31
|
+
# Functional test for the widget.
|
32
|
+
m.template 'cell_test.rb', File.join('test/cells/', "#{file_name}_cell_test.rb"), :assigns => {:states => actions}
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class <%= class_name %>CellTest < ActionController::TestCase
|
4
|
+
include Cells::AssertionsHelper
|
5
|
+
|
6
|
+
<% for state in states -%>
|
7
|
+
test "<%= state %>" do
|
8
|
+
html = render_cell(:<%= file_name %>, :<%= state %>)
|
9
|
+
#assert_selekt html, "div"
|
10
|
+
end
|
11
|
+
|
12
|
+
<% end %>
|
13
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
3
|
+
|
4
|
+
class AssertionsHelperTest < ActionController::TestCase
|
5
|
+
context "A TestCase" do
|
6
|
+
setup do
|
7
|
+
TestCell.class_eval do
|
8
|
+
def beep; render; end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "calling #cell_mock" do
|
13
|
+
should "return a cell instance" do
|
14
|
+
assert_kind_of Cell::Base, cell_mock
|
15
|
+
end
|
16
|
+
|
17
|
+
should "accept a block" do
|
18
|
+
assert_respond_to cell_mock { def beep; end}, :beep
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
should "respond to #render_cell" do
|
23
|
+
assert_equal "<h1>beep!</h1>", render_cell(:test, :beep)
|
24
|
+
end
|
25
|
+
|
26
|
+
should "respond to #assert_selekt" do
|
27
|
+
assert_selekt render_cell(:test, :beep), "h1", "beep!"
|
28
|
+
end
|
29
|
+
|
30
|
+
should "respond to #cell" do
|
31
|
+
assert_kind_of TestCell, cell(:test)
|
32
|
+
assert_not cell(:test).respond_to? :opts
|
33
|
+
end
|
34
|
+
|
35
|
+
should "respond to #cell with a block" do
|
36
|
+
assert_respond_to cell(:test) { def opts; @opts; end }, :opts
|
37
|
+
end
|
38
|
+
|
39
|
+
should "respond to #cell with options and block" do
|
40
|
+
assert_equal({:topic => :peace}, cell(:test, :topic => :peace) { def opts; @opts; end }.opts)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[test_helper])
|
2
|
+
require 'rails_generator'
|
3
|
+
require 'rails_generator/scripts/generate'
|
4
|
+
|
5
|
+
# for some reasons the "autoloading" in Rails::Generator::Lookup doesn't work:
|
6
|
+
Rails::Generator::Base.append_sources Rails::Generator::PathSource.new(:cells, File.join(File.dirname(__FILE__)+'/../rails_generators'))
|
7
|
+
|
8
|
+
class CellGeneratorTest < Test::Unit::TestCase
|
9
|
+
context "Running script/generate cell" do
|
10
|
+
setup do
|
11
|
+
FileUtils.mkdir_p(fake_rails_root)
|
12
|
+
@original_files = file_list
|
13
|
+
end
|
14
|
+
|
15
|
+
teardown do
|
16
|
+
FileUtils.rm_r(fake_rails_root)
|
17
|
+
end
|
18
|
+
|
19
|
+
context "Blog post latest" do
|
20
|
+
should "create the standard assets" do
|
21
|
+
Rails::Generator::Scripts::Generate.new.run(%w(cell Blog post latest), :destination => fake_rails_root)
|
22
|
+
files = (file_list - @original_files)
|
23
|
+
assert files.include?(fake_rails_root+"/app/cells/blog_cell.rb")
|
24
|
+
assert files.include?(fake_rails_root+"/app/cells/blog/post.html.erb")
|
25
|
+
assert files.include?(fake_rails_root+"/app/cells/blog/latest.html.erb")
|
26
|
+
assert files.include?(fake_rails_root+"/test/cells/blog_cell_test.rb")
|
27
|
+
end
|
28
|
+
|
29
|
+
should "create haml assets with --haml" do
|
30
|
+
Rails::Generator::Scripts::Generate.new.run(%w(cell Blog post latest --haml), :destination => fake_rails_root)
|
31
|
+
files = (file_list - @original_files)
|
32
|
+
assert files.include?(fake_rails_root+"/app/cells/blog_cell.rb")
|
33
|
+
assert files.include?(fake_rails_root+"/app/cells/blog/post.html.haml")
|
34
|
+
assert files.include?(fake_rails_root+"/app/cells/blog/latest.html.haml")
|
35
|
+
assert files.include?(fake_rails_root+"/test/cells/blog_cell_test.rb")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def fake_rails_root
|
42
|
+
File.join(File.dirname(__FILE__), 'rails_root')
|
43
|
+
end
|
44
|
+
|
45
|
+
def file_list
|
46
|
+
Dir.glob(File.join(fake_rails_root, "**/*"))
|
47
|
+
end
|
48
|
+
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require 'action_controller/test_case'
|
3
|
-
|
4
|
-
# Assertion helpers extracted from Devise by José Valim.
|
5
|
-
#
|
6
2
|
module Cells
|
7
|
-
|
3
|
+
# Assertion helpers extracted from Devise by José Valim.
|
4
|
+
#
|
5
|
+
module InternalAssertionsHelper
|
8
6
|
def setup
|
7
|
+
### TODO: clean up CellsTestController.
|
9
8
|
@controller = ::CellsTestController.new
|
10
9
|
@request = ::ActionController::TestRequest.new
|
11
10
|
@response = ::ActionController::TestResponse.new
|
@@ -13,11 +12,7 @@ module Cells
|
|
13
12
|
@controller.response = @response
|
14
13
|
@controller.params = {}
|
15
14
|
end
|
16
|
-
|
17
|
-
def assert_selekt(content, *args)
|
18
|
-
assert_select(HTML::Document.new(content).root, *args)
|
19
|
-
end
|
20
|
-
|
15
|
+
|
21
16
|
def assert_not(assertion)
|
22
17
|
assert !assertion
|
23
18
|
end
|
@@ -56,5 +51,14 @@ module Cells
|
|
56
51
|
object.send :"#{key}=", value
|
57
52
|
end
|
58
53
|
end
|
54
|
+
|
55
|
+
# Provides a TestCell instance. The <tt>block</tt> is passed to instance_eval and should be used
|
56
|
+
# to extend the mock on the fly.
|
57
|
+
### DISCUSS: make an anonymous subclass of TestCell?
|
58
|
+
def cell_mock(options={}, &block)
|
59
|
+
cell = TestCell.new(@controller, options)
|
60
|
+
cell.instance_eval(&block) if block_given?
|
61
|
+
cell
|
62
|
+
end
|
59
63
|
end
|
60
|
-
end
|
64
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -29,6 +29,13 @@ rescue
|
|
29
29
|
require 'action_view'
|
30
30
|
end
|
31
31
|
|
32
|
+
begin
|
33
|
+
require 'shoulda'
|
34
|
+
rescue
|
35
|
+
gem 'shoulda'
|
36
|
+
require 'shoulda'
|
37
|
+
end
|
38
|
+
|
32
39
|
require 'active_support/test_case'
|
33
40
|
|
34
41
|
# Require app's test_helper.rb if such exists.
|
@@ -61,7 +68,9 @@ end
|
|
61
68
|
|
62
69
|
# Load test support files.
|
63
70
|
Dir[File.join(File.dirname(__FILE__), *%w[support ** *.rb]).to_s].each { |f| require f }
|
71
|
+
require File.join(File.dirname(__FILE__), *%w[.. lib cells assertions_helper])
|
64
72
|
|
65
73
|
ActiveSupport::TestCase.class_eval do
|
66
74
|
include Cells::AssertionsHelper
|
75
|
+
include Cells::InternalAssertionsHelper
|
67
76
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cells
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-03-27 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -26,16 +26,9 @@ files:
|
|
26
26
|
- MIT-LICENSE
|
27
27
|
- README.rdoc
|
28
28
|
- Rakefile
|
29
|
-
- generators/cell/USAGE
|
30
|
-
- generators/cell/cell_generator.rb
|
31
|
-
- generators/cell/templates/cell.rb
|
32
|
-
- generators/cell/templates/view.html.erb
|
33
|
-
- generators/cell/templates/view.html.haml
|
34
|
-
- generators/cells_install/USAGE
|
35
|
-
- generators/cells_install/cells_install_generator.rb
|
36
|
-
- generators/cells_install/templates/initializer.rb
|
37
29
|
- lib/cell.rb
|
38
30
|
- lib/cells.rb
|
31
|
+
- lib/cells/assertions_helper.rb
|
39
32
|
- lib/cells/cell.rb
|
40
33
|
- lib/cells/cell/base.rb
|
41
34
|
- lib/cells/cell/caching.rb
|
@@ -47,6 +40,15 @@ files:
|
|
47
40
|
- lib/cells/rails/action_view.rb
|
48
41
|
- lib/cells/version.rb
|
49
42
|
- rails/init.rb
|
43
|
+
- rails_generators/cell/USAGE
|
44
|
+
- rails_generators/cell/cell_generator.rb
|
45
|
+
- rails_generators/cell/templates/cell.rb
|
46
|
+
- rails_generators/cell/templates/cell_test.rb
|
47
|
+
- rails_generators/cell/templates/view.html.erb
|
48
|
+
- rails_generators/cell/templates/view.html.haml
|
49
|
+
- rails_generators/cells_install/USAGE
|
50
|
+
- rails_generators/cells_install/cells_install_generator.rb
|
51
|
+
- rails_generators/cells_install/templates/initializer.rb
|
50
52
|
has_rdoc: true
|
51
53
|
homepage: http://cells.rubyforge.org
|
52
54
|
licenses: []
|
@@ -76,20 +78,22 @@ signing_key:
|
|
76
78
|
specification_version: 3
|
77
79
|
summary: Cells are lightweight controllers for Rails and can be rendered in controllers and views, providing an elegant and fast way for encapsulation and component-orientation.
|
78
80
|
test_files:
|
79
|
-
- test/caching_test.rb
|
80
|
-
- test/cells_test.rb
|
81
|
-
- test/test_helper.rb
|
82
|
-
- test/capture_helper_test.rb
|
83
81
|
- test/rails_test.rb
|
84
|
-
- test/
|
82
|
+
- test/capture_helper_test.rb
|
83
|
+
- test/assertions_helper_test.rb
|
84
|
+
- test/cell_generator_test.rb
|
85
|
+
- test/test_helper.rb
|
86
|
+
- test/support/internal_assertions_helper.rb
|
85
87
|
- test/bugs_test.rb
|
86
88
|
- test/render_test.rb
|
87
|
-
- test/
|
88
|
-
- test/
|
89
|
-
- test/
|
90
|
-
- test/app/
|
91
|
-
- test/app/cells/test_cell.rb
|
92
|
-
- test/app/cells/cells_test_one_cell.rb
|
89
|
+
- test/cells_test.rb
|
90
|
+
- test/helper_test.rb
|
91
|
+
- test/caching_test.rb
|
92
|
+
- test/app/controllers/cells_test_controller.rb
|
93
93
|
- test/app/cells/really_module/nested_cell.rb
|
94
|
+
- test/app/cells/cells_test_one_cell.rb
|
95
|
+
- test/app/cells/cells_test_two_cell.rb
|
94
96
|
- test/app/cells/simple_cell.rb
|
95
|
-
- test/app/
|
97
|
+
- test/app/cells/test_cell.rb
|
98
|
+
- test/app/helpers/application_helper.rb
|
99
|
+
- test/app/helpers/helper_using_cell_helper.rb
|