cells 3.3.4 → 3.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,33 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (2.3.9)
5
+ actionpack (= 2.3.9)
6
+ actionpack (2.3.9)
7
+ activesupport (= 2.3.9)
8
+ rack (~> 1.1.0)
9
+ active_helper (0.2.2)
10
+ activesupport (>= 2.3.0)
11
+ activerecord (2.3.9)
12
+ activesupport (= 2.3.9)
13
+ activeresource (2.3.9)
14
+ activesupport (= 2.3.9)
15
+ activesupport (2.3.9)
16
+ rack (1.1.0)
17
+ rails (2.3.9)
18
+ actionmailer (= 2.3.9)
19
+ actionpack (= 2.3.9)
20
+ activerecord (= 2.3.9)
21
+ activeresource (= 2.3.9)
22
+ activesupport (= 2.3.9)
23
+ rake (>= 0.8.3)
24
+ rake (0.8.7)
25
+ shoulda (2.11.3)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ active_helper
32
+ rails (~> 2.3)
33
+ shoulda
@@ -66,3 +66,4 @@ end
66
66
  Cell::Base.view_paths = Cells::DEFAULT_VIEW_PATHS if Cell::Base.view_paths.blank?
67
67
 
68
68
  require 'cells/rails'
69
+ require 'cells/cell/test_case' if ENV['RAILS_ENV'] = 'test'
@@ -0,0 +1,135 @@
1
+ require "active_support/test_case"
2
+ module Cell
3
+ # Test your cells.
4
+ #
5
+ # This class is roughly equal to ActionController::TestCase, exposing the same semantics. It will try
6
+ # to infer the tested cell name from the test name if you use declarative testing. You can also set it
7
+ # with TestCase.tests.
8
+ #
9
+ # A declarative test would look like
10
+ #
11
+ # class SellOutTest < Cell::TestCase
12
+ # tests ShoppingCartCell
13
+ #
14
+ # it "should be rendered nicely" do
15
+ # invoke :order_button, :items => @fixture_items
16
+ #
17
+ # assert_select "button", "Order now!"
18
+ # end
19
+ #
20
+ # You can also do stuff yourself, like
21
+ #
22
+ # it "should be rendered even nicer" do
23
+ # html = render_cell(:shopping_cart, :order_button, , :items => @fixture_items)
24
+ # assert_selector "button", "Order now!", html
25
+ # end
26
+ #
27
+ # Or even unit test your cell:
28
+ #
29
+ # it "should provide #default_items" do
30
+ # assert_equal [@item1, @item2], cell(:shopping_cart).default_items
31
+ # end
32
+ #
33
+ # == Test helpers
34
+ #
35
+ # Basically, we got these new methods:
36
+ #
37
+ # +invoke+:: Renders the passed +state+ with your tested cell. You may pass options like in #render_cell.
38
+ # +render_cell+:: As in your views. Will return the rendered view.
39
+ # +assert_selector+:: Like #assert_select except that the last argument is the html markup you wanna test.
40
+ # +cell+:: Gives you a cell instance for unit testing and stuff.
41
+ class TestCase < ActiveSupport::TestCase
42
+ module AssertSelect
43
+ # Invokes assert_select for the last argument, the +content+ string.
44
+ #
45
+ # Example:
46
+ # assert_selector "h1", "The latest and greatest!", "<h1>The latest and greatest!</h1>"
47
+ #
48
+ # would be true.
49
+ def assert_selector(*args, &block)
50
+ rails_assert_select(HTML::Document.new(args.pop).root, *args, &block)
51
+ end
52
+
53
+ # Invokes assert_select on the markup set by the last #invoke.
54
+ #
55
+ # Example:
56
+ # invoke :latest
57
+ # assert_select "h1", "The latest and greatest!"
58
+ def assert_select(*args, &block)
59
+ super(HTML::Document.new(last_invoke).root, *args, &block)
60
+ end
61
+ end
62
+
63
+ module TestMethods
64
+ def setup
65
+ @controller = Class.new(ActionController::Base).new
66
+ @request = ::ActionController::TestRequest.new
67
+ @response = ::ActionController::TestResponse.new
68
+ @controller.request = @request
69
+ @controller.response = @response
70
+ @controller.params = {}
71
+ end
72
+
73
+ # Use this for functional tests of your application cells.
74
+ #
75
+ # Example:
76
+ # should "spit out a h1 title" do
77
+ # html = render_cell(:news, :latest)
78
+ # assert_selekt html, "h1", "The latest and greatest!"
79
+ def render_cell(*args)
80
+ @controller.render_cell(*args)
81
+ end
82
+
83
+ # Builds an instance of <tt>name</tt>Cell for unit testing.
84
+ # Passes the optional block to <tt>cell.instance_eval</tt>.
85
+ #
86
+ # Example:
87
+ # assert_equal "Banks kill planet!" cell(:news, :topic => :terror).latest_headline
88
+ def cell(name, opts={}, &block)
89
+ cell = ::Cell::Base.create_cell_for(@controller, name, opts)
90
+ cell.instance_eval &block if block_given?
91
+ cell
92
+ end
93
+ end
94
+
95
+ include TestMethods
96
+ include ActionController::Assertions::SelectorAssertions # imports "their" #assert_select.
97
+ alias_method :rails_assert_select, :assert_select # i hate that.
98
+ include AssertSelect
99
+
100
+
101
+ attr_reader :last_invoke
102
+
103
+ def invoke(state, *args)
104
+ @last_invoke = self.class.controller_class.new(@controller, *args).render_state(state)
105
+ end
106
+
107
+
108
+ class << self
109
+ # Sets the controller class name. Useful if the name can't be inferred from test class.
110
+ # Expects +controller_class+ as a constant. Example: <tt>tests WidgetController</tt>.
111
+ def tests(controller_class)
112
+ self.controller_class = controller_class
113
+ end
114
+
115
+ def controller_class=(new_class)
116
+ write_inheritable_attribute(:controller_class, new_class)
117
+ end
118
+
119
+ def controller_class
120
+ if current_controller_class = read_inheritable_attribute(:controller_class)
121
+ current_controller_class
122
+ else
123
+ self.controller_class = determine_default_controller_class(name)
124
+ end
125
+ end
126
+
127
+ def determine_default_controller_class(name)
128
+ name.sub(/Test$/, '').constantize
129
+ rescue NameError
130
+ nil
131
+ end
132
+ end
133
+
134
+ end
135
+ end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Cells
4
- VERSION = '3.3.4'
4
+ VERSION = '3.3.5'
5
5
  end
@@ -0,0 +1,9 @@
1
+ namespace :log do
2
+ desc "Truncates all *.log files in log/ to zero bytes"
3
+ task :cleeeeear do
4
+ FileList["log/*.log"].each do |log_file|
5
+ f = File.open(log_file, "w")
6
+ f.close
7
+ end
8
+ end
9
+ end
@@ -1,12 +1,10 @@
1
- # encoding: utf-8
2
-
3
1
  class CellsInstallGenerator < Rails::Generator::Base
4
-
5
2
  def manifest
6
3
  record do |m|
7
4
  m.directory File.join('config', 'initializers')
5
+ m.directory File.join('lib', 'tasks')
8
6
  m.template 'initializer.rb', File.join('config', 'initializers', 'cells.rb')
7
+ m.template 'tasks.rake', File.join('lib', 'tasks', 'cells.rake')
9
8
  end
10
9
  end
11
-
12
- end
10
+ end
@@ -0,0 +1,6 @@
1
+ namespace "test" do
2
+ Rake::TestTask.new(:cells) do |t|
3
+ t.libs << "test"
4
+ t.pattern = 'test/cells/**/*_test.rb'
5
+ end
6
+ end
@@ -0,0 +1,78 @@
1
+ require 'test_helper'
2
+
3
+ class TestCaseTest < Cell::TestCase
4
+
5
+ context "A TestCase" do
6
+ setup do
7
+ @test = Cell::TestCase.new(:cell_test)
8
+
9
+ BassistCell.class_eval do
10
+ def play; render; end
11
+ end
12
+ end
13
+
14
+
15
+ should "respond to #render_cell" do
16
+ assert_equal "Doo", render_cell(:bassist, :play)
17
+ end
18
+
19
+ should "respond to #assert_selector with 3 args" do
20
+ assert_selector "p", "Doo", "<p>Doo</p>y"
21
+ end
22
+
23
+ should "respond to #cell" do
24
+ assert_kind_of BassistCell, cell(:bassist)
25
+ assert !cell(:bassist).respond_to?(:opts)
26
+ end
27
+
28
+ should "respond to #cell with a block" do
29
+ assert_respond_to cell(:bassist) { def opts; @opts; end }, :opts
30
+ end
31
+
32
+ should "respond to #cell with options and block" do
33
+ assert_equal({:topic => :peace}, cell(:bassist, :topic => :peace) { def opts; @opts; end }.opts)
34
+ end
35
+
36
+ context "in declarative tests" do
37
+ should "respond to TestCase.tests" do
38
+ self.class.tests BassistCell
39
+ assert_equal BassistCell, self.class.controller_class
40
+ end
41
+
42
+ should "infer the cell name" do
43
+ class SingerCell < Cell::Base
44
+ end
45
+
46
+ class SingerCellTest < Cell::TestCase
47
+ end
48
+
49
+ assert_equal SingerCell, SingerCellTest.new(:cell_test).class.controller_class
50
+ end
51
+
52
+ context "with invoke" do
53
+ setup do
54
+ self.class.tests BassistCell
55
+ end
56
+
57
+ should "provide #invoke" do
58
+ assert_equal "Doo", invoke(:play)
59
+ end
60
+
61
+ should "provide #last_invoke" do
62
+ assert_equal nil, last_invoke
63
+ assert_equal "Doo", invoke(:play)
64
+ assert_equal "Doo", last_invoke
65
+ end
66
+
67
+ should "provide #invoke accepting opts" do
68
+ #assert_equal "Doo", invoke(:play)
69
+ end
70
+
71
+ should "provide assert_select" do
72
+ invoke :play
73
+ assert_select "a", 0
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cells
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.4
4
+ hash: 1
5
+ prerelease: false
6
+ segments:
7
+ - 3
8
+ - 3
9
+ - 5
10
+ version: 3.3.5
5
11
  platform: ruby
6
12
  authors:
7
13
  - Nick Sutterer
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-06-28 00:00:00 +02:00
18
+ date: 2010-10-06 00:00:00 +02:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -24,6 +30,7 @@ extra_rdoc_files:
24
30
  files:
25
31
  - CHANGES
26
32
  - Gemfile
33
+ - Gemfile.lock
27
34
  - MIT-LICENSE
28
35
  - README.rdoc
29
36
  - Rakefile
@@ -34,6 +41,7 @@ files:
34
41
  - lib/cells/cell/active_helper.rb
35
42
  - lib/cells/cell/base.rb
36
43
  - lib/cells/cell/caching.rb
44
+ - lib/cells/cell/test_case.rb
37
45
  - lib/cells/cell/view.rb
38
46
  - lib/cells/helpers.rb
39
47
  - lib/cells/helpers/capture_helper.rb
@@ -42,6 +50,7 @@ files:
42
50
  - lib/cells/rails/action_view.rb
43
51
  - lib/cells/version.rb
44
52
  - rails/init.rb
53
+ - rails/tasks/log.rake
45
54
  - rails_generators/cell/USAGE
46
55
  - rails_generators/cell/cell_generator.rb
47
56
  - rails_generators/cell/templates/cell.rb
@@ -51,6 +60,29 @@ files:
51
60
  - rails_generators/cells_install/USAGE
52
61
  - rails_generators/cells_install/cells_install_generator.rb
53
62
  - rails_generators/cells_install/templates/initializer.rb
63
+ - rails_generators/cells_install/templates/tasks.rake
64
+ - test/rails_test.rb
65
+ - test/active_helper_test.rb
66
+ - test/capture_helper_test.rb
67
+ - test/assertions_helper_test.rb
68
+ - test/cell_generator_test.rb
69
+ - test/test_helper.rb
70
+ - test/support/internal_assertions_helper.rb
71
+ - test/bugs_test.rb
72
+ - test/render_test.rb
73
+ - test/test_case_test.rb
74
+ - test/cells_test.rb
75
+ - test/helper_test.rb
76
+ - test/caching_test.rb
77
+ - test/app/controllers/cells_test_controller.rb
78
+ - test/app/cells/bassist_cell.rb
79
+ - test/app/cells/really_module/nested_cell.rb
80
+ - test/app/cells/cells_test_one_cell.rb
81
+ - test/app/cells/cells_test_two_cell.rb
82
+ - test/app/cells/simple_cell.rb
83
+ - test/app/cells/test_cell.rb
84
+ - test/app/helpers/application_helper.rb
85
+ - test/app/helpers/helper_using_cell_helper.rb
54
86
  has_rdoc: true
55
87
  homepage: http://cells.rubyforge.org
56
88
  licenses: []
@@ -61,21 +93,27 @@ rdoc_options:
61
93
  require_paths:
62
94
  - lib
63
95
  required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
64
97
  requirements:
65
98
  - - ">="
66
99
  - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
67
103
  version: "0"
68
- version:
69
104
  required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
70
106
  requirements:
71
107
  - - ">="
72
108
  - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
73
112
  version: "0"
74
- version:
75
113
  requirements: []
76
114
 
77
115
  rubyforge_project:
78
- rubygems_version: 1.3.5
116
+ rubygems_version: 1.3.7
79
117
  signing_key:
80
118
  specification_version: 3
81
119
  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.
@@ -89,6 +127,7 @@ test_files:
89
127
  - test/support/internal_assertions_helper.rb
90
128
  - test/bugs_test.rb
91
129
  - test/render_test.rb
130
+ - test/test_case_test.rb
92
131
  - test/cells_test.rb
93
132
  - test/helper_test.rb
94
133
  - test/caching_test.rb