cells 3.4.0.beta2 → 3.4.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/README.rdoc +1 -1
  2. data/Rakefile +1 -1
  3. data/lib/cell/rails.rb +0 -9
  4. data/lib/cells/version.rb +1 -1
  5. data/{rails_generators/cell → lib/generators/cells}/USAGE +0 -0
  6. data/lib/generators/cells/cell_generator.rb +45 -0
  7. data/{rails_generators/cell → lib/generators/cells}/templates/cell.rb +0 -0
  8. data/{rails_generators/cell → lib/generators/cells}/templates/cell_test.rb +2 -2
  9. data/lib/generators/cells/templates/view.erb +7 -0
  10. data/lib/generators/cells/templates/view.haml +4 -0
  11. data/{rails_generators → lib/generators}/cells_install/USAGE +0 -0
  12. data/{rails_generators → lib/generators}/cells_install/cells_install_generator.rb +0 -0
  13. data/{rails_generators → lib/generators}/cells_install/templates/initializer.rb +0 -0
  14. data/test/cell_generator_test.rb +31 -40
  15. data/test/dummy/app/controllers/application_controller.rb +4 -0
  16. data/test/{app → dummy/app}/controllers/musician_controller.rb +5 -1
  17. data/test/dummy/app/helpers/application_helper.rb +2 -0
  18. data/test/dummy/config/application.rb +23 -0
  19. data/test/dummy/config/boot.rb +10 -0
  20. data/test/dummy/config/environment.rb +5 -0
  21. data/test/dummy/config/environments/development.rb +19 -0
  22. data/test/dummy/config/environments/production.rb +46 -0
  23. data/test/dummy/config/environments/test.rb +32 -0
  24. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  25. data/test/dummy/config/initializers/inflections.rb +10 -0
  26. data/test/dummy/config/initializers/mime_types.rb +5 -0
  27. data/test/dummy/config/initializers/secret_token.rb +7 -0
  28. data/test/dummy/config/initializers/session_store.rb +8 -0
  29. data/test/dummy/config/routes.rb +3 -0
  30. data/test/dummy/tmp/app/cells/blog_cell.rb +11 -0
  31. data/test/dummy/tmp/test/cells/blog_cell_test.rb +17 -0
  32. data/test/rails/integration_test.rb +1 -11
  33. data/test/rails/router_test.rb +5 -48
  34. data/test/support/internal_assertions_helper.rb +2 -3
  35. data/test/test_helper.rb +5 -6
  36. metadata +75 -48
  37. data/rails_generators/cell/cell_generator.rb +0 -63
  38. data/rails_generators/cell/templates/view.html.haml +0 -4
  39. data/rails_generators/erb/cell_generator.rb +0 -20
  40. data/rails_generators/erb/templates/view.html.erb +0 -2
  41. data/test/abstract_unit.rb +0 -248
  42. data/test/app/controllers/cells_test_controller.rb +0 -44
@@ -29,7 +29,7 @@ Rails 2.3:
29
29
 
30
30
  Creating a cell is nothing more than
31
31
 
32
- $ rails generate cell ShoppingCart display
32
+ $ rails generate cells:cell ShoppingCart display
33
33
  create app/cells/
34
34
  create app/cells/shopping_cart
35
35
  create app/cells/shopping_cart_cell.rb
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ task :default => :test
11
11
  desc 'Test the cells plugin.'
12
12
  Rake::TestTask.new(:test) do |test|
13
13
  test.libs << 'test'
14
- test.pattern = 'test/**/*_test.rb'
14
+ test.test_files = FileList['test/*_test.rb', 'test/rails/*_test.rb']
15
15
  test.verbose = true
16
16
  end
17
17
 
@@ -75,15 +75,6 @@ module Cell
75
75
  delegate :config, :to => :parent_controller # DISCUSS: what if a cell has its own config (eg for assets, cells/bassist/images)?
76
76
  # DISCUSS: let @controller point to @parent_controller in views, and @cell is the actual real controller?
77
77
 
78
-
79
-
80
- class << self
81
- def state2view_cache
82
- @state2view_cache ||= {}
83
- end
84
- end
85
-
86
-
87
78
  # Renders the view for the current state and returns the markup for the component.
88
79
  # Usually called and returned at the end of a state method.
89
80
  #
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Cells
4
- VERSION = '3.4.0.beta2'
4
+ VERSION = '3.4.0.beta3'
5
5
  end
@@ -0,0 +1,45 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/named_base'
3
+
4
+ module Cells
5
+ module Generators
6
+ class CellGenerator < ::Rails::Generators::NamedBase
7
+ argument :actions, :type => :array, :default => [], :banner => "action action"
8
+ check_class_collision :suffix => "Cell"
9
+
10
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
11
+
12
+ class_option :view_engine, :type => :string, :aliases => "-t", :desc => "Template engine for the views. Available options are 'erb' and 'haml'.", :default => "erb"
13
+ class_option :haml, :type => :boolean, :default => false
14
+
15
+
16
+ def create_cell_file
17
+ template 'cell.rb', File.join('app/cells', class_path, "#{file_name}_cell.rb")
18
+ end
19
+
20
+ def create_views
21
+ if options[:view_engine].to_s == "haml" or options[:haml]
22
+ create_views_for(:haml)
23
+ else
24
+ create_views_for(:erb)
25
+ end
26
+ end
27
+
28
+ def create_test
29
+ @states = actions
30
+ template 'cell_test.rb', File.join('test/cells/', "#{file_name}_cell_test.rb")
31
+ end
32
+
33
+ protected
34
+
35
+ def create_views_for(engine)
36
+ for state in actions do
37
+ @state = state
38
+ @path = File.join('app/cells', file_name, "#{state}.html.#{engine}")
39
+
40
+ template "view.#{engine}", @path
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -3,10 +3,10 @@ require 'test_helper'
3
3
  class <%= class_name %>CellTest < ActionController::TestCase
4
4
  include Cells::AssertionsHelper
5
5
 
6
- <% for state in states -%>
6
+ <% for state in @states -%>
7
7
  test "<%= state %>" do
8
8
  html = render_cell(:<%= file_name %>, :<%= state %>)
9
- #assert_selekt html, "div"
9
+ assert_selekt html, "p"
10
10
  end
11
11
 
12
12
  <% end %>
@@ -0,0 +1,7 @@
1
+ <h1>
2
+ <%= class_name %>#<%= @state %>
3
+ </h1>
4
+
5
+ <p>
6
+ Find me in <%= @path %>
7
+ </p>
@@ -0,0 +1,4 @@
1
+ %h1
2
+ <%= class_name %>#<%= @state %>
3
+ %p
4
+ Find me in <%= @path %>
@@ -1,62 +1,53 @@
1
- require File.join(File.dirname(__FILE__), *%w[test_helper])
2
-
3
- #require 'rails/generators/test_unit'
4
-
5
-
6
- #require '/home/nick/projects/rails/railties/lib/rails/test/isolation/abstract_unit'
7
- require 'abstract_unit'
8
-
9
- #require '/home/nick/projects/rails/railties/test/generators/generators_test_helper'
10
- require 'rails/generators'
11
- require 'rails_generators/cell/cell_generator'
12
- module Rails
13
- def self.root
14
- @root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures'))
15
- end
16
- end
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
17
2
 
3
+ require 'generators/cells/cell_generator'
18
4
 
19
5
  class CellGeneratorTest < Rails::Generators::TestCase
20
6
  destination File.join(Rails.root, "tmp")
21
7
  setup :prepare_destination
22
8
  tests ::Cells::Generators::CellGenerator
23
-
24
-
9
+
25
10
  context "Running script/generate cell" do
26
11
  context "Blog post latest" do
27
12
  should "create the standard assets" do
28
13
 
29
- require "#{app_path}/config/environment" # we need Rails.application
30
-
31
-
32
- run_generator ["Blog", "post", "latest"]
14
+ run_generator %w(Blog post latest)
33
15
 
34
16
  assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
17
+ assert_file "app/cells/blog_cell.rb", /def post/
18
+ assert_file "app/cells/blog_cell.rb", /def latest/
35
19
  assert_file "app/cells/blog/post.html.erb", %r(app/cells/blog/post\.html\.erb)
20
+ assert_file "app/cells/blog/post.html.erb", %r(<p>)
36
21
  assert_file "app/cells/blog/latest.html.erb", %r(app/cells/blog/latest\.html\.erb)
37
22
 
38
- #assert files.include?(fake_rails_root+"/app/cells/blog/post.html.erb")
39
- #assert files.include?(fake_rails_root+"/app/cells/blog/latest.html.erb")
40
- #assert files.include?(fake_rails_root+"/test/cells/blog_cell_test.rb")
23
+ assert_file "test/cells/blog_cell_test.rb"
41
24
  end
42
25
 
43
26
  should "create haml assets with --haml" do
44
- run_generator ["Blog", "post", "latest", "--haml"]
45
- files = (file_list - @original_files)
46
- assert files.include?(fake_rails_root+"/app/cells/blog_cell.rb")
47
- assert files.include?(fake_rails_root+"/app/cells/blog/post.html.haml")
48
- assert files.include?(fake_rails_root+"/app/cells/blog/latest.html.haml")
49
- assert files.include?(fake_rails_root+"/test/cells/blog_cell_test.rb")
27
+ run_generator %w(Blog post latest --haml)
28
+
29
+ assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
30
+ assert_file "app/cells/blog_cell.rb", /def post/
31
+ assert_file "app/cells/blog_cell.rb", /def latest/
32
+ assert_file "app/cells/blog/post.html.haml", %r(app/cells/blog/post\.html\.haml)
33
+ assert_file "app/cells/blog/post.html.haml", %r(%p)
34
+ assert_file "app/cells/blog/latest.html.haml", %r(app/cells/blog/latest\.html\.haml)
35
+
36
+ assert_file "test/cells/blog_cell_test.rb"
37
+ end
38
+
39
+ should "create haml assets with -t haml" do
40
+ run_generator %w(Blog post latest -t haml)
41
+
42
+ assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
43
+ assert_file "app/cells/blog_cell.rb", /def post/
44
+ assert_file "app/cells/blog_cell.rb", /def latest/
45
+ assert_file "app/cells/blog/post.html.haml", %r(app/cells/blog/post\.html\.haml)
46
+ assert_file "app/cells/blog/post.html.haml", %r(%p)
47
+ assert_file "app/cells/blog/latest.html.haml", %r(app/cells/blog/latest\.html\.haml)
48
+
49
+ assert_file "test/cells/blog_cell_test.rb"
50
50
  end
51
51
  end
52
52
  end
53
-
54
- private
55
- def fake_rails_root
56
- File.join(File.dirname(__FILE__), 'rails_root')
57
- end
58
-
59
- def file_list
60
- Dir.glob(File.join(fake_rails_root, "**/*"))
61
- end
62
53
  end
@@ -0,0 +1,4 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ layout 'application'
4
+ end
@@ -1,4 +1,8 @@
1
1
  class MusicianController < ActionController::Base
2
+ def index
3
+ render :text => render_cell(:bassist, :promote)
4
+ end
5
+
2
6
  def promotion
3
7
  render :text => render_cell(:bassist, :provoke)
4
8
  end
@@ -13,5 +17,5 @@ class MusicianController < ActionController::Base
13
17
  def hamlet
14
18
  end
15
19
 
16
- def action_method?(name); true; end ### FIXME: fixes NameError: undefined local variable or method `_router' for MusicianController:Class
20
+ #def action_method?(name); true; end ### FIXME: fixes NameError: undefined local variable or method `_router' for MusicianController:Class
17
21
  end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "active_model/railtie"
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_view/railtie"
7
+ require "action_mailer/railtie"
8
+
9
+ Bundler.require
10
+
11
+
12
+ require "cells"
13
+
14
+ #require "rails_app"
15
+
16
+ module Dummy
17
+ class Application < Rails::Application
18
+ config.encoding = "utf-8"
19
+
20
+ # Configure sensitive parameters which will be filtered from the log file.
21
+ config.filter_parameters += [:password]
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,19 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/environment.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the webserver when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_view.debug_rjs = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Don't care if the mailer can't send
18
+ config.action_mailer.raise_delivery_errors = false
19
+ end
@@ -0,0 +1,46 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/environment.rb
3
+
4
+ # The production environment is meant for finished, "live" apps.
5
+ # Code is not reloaded between requests
6
+ config.cache_classes = true
7
+
8
+ # Full error reports are disabled and caching is turned on
9
+ config.consider_all_requests_local = false
10
+ config.action_controller.perform_caching = true
11
+
12
+ # Specifies the header that your server uses for sending files
13
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
14
+
15
+ # For nginx:
16
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
17
+
18
+ # If you have no front-end server that supports something like X-Sendfile,
19
+ # just comment this out and Rails will serve the files
20
+
21
+ # See everything in the log (default is :info)
22
+ # config.log_level = :debug
23
+
24
+ # Use a different logger for distributed setups
25
+ # config.logger = SyslogLogger.new
26
+
27
+ # Use a different cache store in production
28
+ # config.cache_store = :mem_cache_store
29
+
30
+ # Disable Rails's static asset server
31
+ # In production, Apache or nginx will already do this
32
+ config.serve_static_assets = false
33
+
34
+ # Enable serving of images, stylesheets, and javascripts from an asset server
35
+ # config.action_controller.asset_host = "http://assets.example.com"
36
+
37
+ # Disable delivery errors, bad email addresses will be ignored
38
+ # config.action_mailer.raise_delivery_errors = false
39
+
40
+ # Enable threaded mode
41
+ # config.threadsafe!
42
+
43
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
44
+ # the I18n.default_locale when a translation can not be found)
45
+ config.i18n.fallbacks = true
46
+ end
@@ -0,0 +1,32 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/environment.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Log error messages when you accidentally call methods on nil.
11
+ config.whiny_nils = true
12
+
13
+ # Show full error reports and disable caching
14
+ config.consider_all_requests_local = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Raise exceptions instead of rendering exception templates
18
+ config.action_dispatch.show_exceptions = false
19
+
20
+ # Disable request forgery protection in test environment
21
+ config.action_controller.allow_forgery_protection = false
22
+
23
+ # Tell Action Mailer not to deliver emails to the real world.
24
+ # The :test delivery method accumulates sent emails in the
25
+ # ActionMailer::Base.deliveries array.
26
+ config.action_mailer.delivery_method = :test
27
+
28
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
29
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
30
+ # like if you have constraints or database-specific column types
31
+ # config.active_record.schema_format = :sql
32
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Rails.application.config.secret_token = '23095eafa1295bcba382a25a812c42e9ddde1c17b4e55ebcd6836a2a81ec0b308a25743686a9d7cd97237a66be1a49a82ac395fbdbb8f895a8e957e4833659bc'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Rails.application.config.session_store :cookie_store, :key => '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rake db:sessions:create")
8
+ # Rails.application.config.session_store :active_record_store
@@ -0,0 +1,3 @@
1
+ Dummy::Application.routes.draw do |map|
2
+ match ':controller(/:action(/:id(.:format)))'
3
+ end
@@ -0,0 +1,11 @@
1
+ class BlogCell < Cell::Rails
2
+
3
+ def post
4
+ render
5
+ end
6
+
7
+ def latest
8
+ render
9
+ end
10
+
11
+ end
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ class BlogCellTest < ActionController::TestCase
4
+ include Cells::AssertionsHelper
5
+
6
+ test "post" do
7
+ html = render_cell(:blog, :post)
8
+ assert_selekt html, "p"
9
+ end
10
+
11
+ test "latest" do
12
+ html = render_cell(:blog, :latest)
13
+ assert_selekt html, "p"
14
+ end
15
+
16
+
17
+ end
@@ -1,19 +1,9 @@
1
1
  require File.join(File.dirname(__FILE__), '/../test_helper')
2
2
 
3
3
  class RailsIntegrationTest < ActionController::TestCase
4
+ tests MusicianController
4
5
 
5
6
  context "A Rails controller" do
6
-
7
- setup do
8
- @routes = ActionDispatch::Routing::RouteSet.new
9
- @routes.draw do
10
- |map| match ':action', :to => MusicianController
11
- end
12
-
13
- @controller = MusicianController.new
14
- @controller.view_paths << File.expand_path(File.join(File.dirname(__FILE__), '../app/views'))
15
- end
16
-
17
7
  should "respond to render_cell" do
18
8
  get 'promotion'
19
9
  assert_equal "That's me, naked <img alt=\"Me\" src=\"/images/me.png\" />", @response.body
@@ -1,45 +1,9 @@
1
- #require '/home/nick/projects/rails/railties/lib/rails/test/isolation/abstract_unit'
2
- require 'abstract_unit'
3
-
4
1
  module ApplicationTests
5
2
  class RouterTest < ActionController::TestCase#Test::Unit::TestCase
6
- include ActiveSupport::Testing::Isolation
7
-
8
-
9
- def app
10
- #@app ||= begin
11
- Rails.application
12
- #end
13
- end
3
+ tests MusicianController
14
4
 
15
5
  context "A Rails app" do
16
- setup do
17
- build_app
18
- FileUtils.rm_rf("#{app_path}/config/environments") # otherwise we get a undefined method `action_mailer' for #<Rails::Application::Configuration
19
-
20
- require "#{app_path}/config/environment" # DISCUSS: introduce #initialize_rails?
21
- boot_rails
22
-
23
- app_file "config/routes.rb", <<-RUBY
24
- AppTemplate::Application.routes.draw do |map|
25
- match '/cell', :to => 'omg#index'
26
- end
27
- RUBY
28
-
29
-
30
- require 'rack/test'
31
- extend Rack::Test::Methods # needs @routes.
32
- end
33
-
34
6
  should "allow cells to use url_helpers" do
35
- controller "omg", <<-RUBY
36
- class OmgController < ActionController::Base
37
- def index
38
- render :text => render_cell(:bassist, :promote)
39
- end
40
- end
41
- RUBY
42
-
43
7
  BassistCell.class_eval do
44
8
  def promote; render; end
45
9
  end
@@ -47,27 +11,20 @@ module ApplicationTests
47
11
  #assert ::Cell::Rails.view_context_class._routes, "Cells::Railtie initializer wasn't invoked."
48
12
  #assert ! ::OmgController.new.respond_to?( :render_cell)
49
13
 
50
- get "/cell"
14
+ get "index"
51
15
  assert_response :success
52
- assert_equal "Find me at <a href=\"/cell\">vd.com</a>", last_response.body
16
+ assert_equal "Find me at <a href=\"/musician\">vd.com</a>", @response.body
53
17
  end
54
18
 
55
19
  should "allow cells to use #config" do
56
- controller "omg", <<-RUBY
57
- class OmgController < ActionController::Base
58
- def index
59
- render :text => render_cell(:bassist, :provoke)
60
- end
61
- end
62
- RUBY
63
20
 
64
21
  BassistCell.class_eval do
65
22
  def provoke; render; end
66
23
  end
67
24
 
68
- get "/cell"
25
+ get "promotion"
69
26
  assert_response :success
70
- assert_equal "That's me, naked <img alt=\"Me\" src=\"/images/me.png\" />", last_response.body
27
+ assert_equal "That's me, naked <img alt=\"Me\" src=\"/images/me.png\" />", @response.body
71
28
  end
72
29
  end
73
30
  end
@@ -4,8 +4,7 @@ module Cells
4
4
  #
5
5
  module InternalAssertionsHelper
6
6
  def setup
7
- ### TODO: clean up CellsTestController.
8
- @controller = ::CellsTestController.new
7
+ @controller = ::MusicianController.new
9
8
  @request = ::ActionController::TestRequest.new
10
9
  @response = ::ActionController::TestResponse.new
11
10
  @controller.request = @request
@@ -55,7 +54,7 @@ module Cells
55
54
  # Provides a TestCell instance. The <tt>block</tt> is passed to instance_eval and should be used
56
55
  # to extend the mock on the fly.
57
56
  ### DISCUSS: make an anonymous subclass of TestCell?
58
- def cell_mock(options={}, &block)
57
+ def cell_mock(options={}, &block) ### DISCUSS: 2BRM.
59
58
  cell = TestCell.new(@controller, options)
60
59
  cell.instance_eval(&block) if block_given?
61
60
  cell
@@ -10,6 +10,11 @@ Bundler.setup
10
10
 
11
11
  ENV['RAILS_ENV'] = 'test'
12
12
 
13
+ $:.unshift File.dirname(__FILE__) # add current dir to LOAD_PATHS
14
+
15
+ require "dummy/config/environment"
16
+ require "rails/test_help" # adds stuff like @routes, etc.
17
+
13
18
  gem_dir = File.join(File.dirname(__FILE__), '..')
14
19
  test_app_dir = File.join(gem_dir, 'test', 'app')
15
20
 
@@ -22,12 +27,6 @@ Cell::Rails.append_view_path(File.join(test_app_dir, 'cells'))
22
27
  Cell::Rails.append_view_path(File.join(test_app_dir, 'cells', 'layouts'))
23
28
 
24
29
 
25
- # Now, load the controllers.
26
- require File.join(test_app_dir, 'controllers', 'cells_test_controller')
27
- require File.join(test_app_dir, 'controllers', 'musician_controller')
28
-
29
-
30
-
31
30
  Dir[File.join(gem_dir, 'test', 'support', '**', '*.rb')].each { |f| require f }
32
31
  require File.join(gem_dir, 'lib', 'cells', 'assertions_helper')
33
32
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cells
3
3
  version: !ruby/object:Gem::Version
4
- hash: -415343653
4
+ hash: 964335479
5
5
  prerelease: true
6
6
  segments:
7
7
  - 3
8
8
  - 4
9
9
  - 0
10
- - beta2
11
- version: 3.4.0.beta2
10
+ - beta3
11
+ version: 3.4.0.beta3
12
12
  platform: ruby
13
13
  authors:
14
14
  - Nick Sutterer
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-09-09 00:00:00 +02:00
19
+ date: 2010-09-15 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies: []
22
22
 
@@ -47,38 +47,51 @@ files:
47
47
  - lib/cells/helpers/capture_helper.rb
48
48
  - lib/cells/rails.rb
49
49
  - lib/cells/version.rb
50
- - rails_generators/cell/USAGE
51
- - rails_generators/cell/cell_generator.rb
52
- - rails_generators/cell/templates/cell.rb
53
- - rails_generators/cell/templates/cell_test.rb
54
- - rails_generators/cell/templates/view.html.haml
55
- - rails_generators/cells_install/USAGE
56
- - rails_generators/cells_install/cells_install_generator.rb
57
- - rails_generators/cells_install/templates/initializer.rb
58
- - rails_generators/erb/cell_generator.rb
59
- - rails_generators/erb/templates/view.html.erb
60
- - test/active_helper_test.rb
61
- - test/abstract_unit.rb
62
- - test/base_methods_test.rb
50
+ - lib/generators/cells/USAGE
51
+ - lib/generators/cells/cell_generator.rb
52
+ - lib/generators/cells/templates/cell.rb
53
+ - lib/generators/cells/templates/cell_test.rb
54
+ - lib/generators/cells/templates/view.erb
55
+ - lib/generators/cells/templates/view.haml
56
+ - lib/generators/cells_install/USAGE
57
+ - lib/generators/cells_install/cells_install_generator.rb
58
+ - lib/generators/cells_install/templates/initializer.rb
63
59
  - test/assertions_helper_test.rb
64
- - test/rails/router_test.rb
65
- - test/rails/view_test.rb
66
- - test/rails/capture_test.rb
67
- - test/rails/integration_test.rb
68
- - test/rails/render_test.rb
69
- - test/rails/cells_test.rb
70
- - test/rails/caching_test.rb
71
- - test/cell_generator_test.rb
72
60
  - test/test_helper.rb
73
- - test/support/internal_assertions_helper.rb
74
- - test/helper_test.rb
75
- - test/app/controllers/musician_controller.rb
76
- - test/app/controllers/cells_test_controller.rb
61
+ - test/app/cells/bad_guitarist_cell.rb
77
62
  - test/app/cells/bassist_cell.rb
78
63
  - test/app/cells/test_cell.rb
79
- - test/app/cells/bad_guitarist_cell.rb
80
- - test/app/helpers/application_helper.rb
81
64
  - test/app/helpers/helper_using_cell_helper.rb
65
+ - test/app/helpers/application_helper.rb
66
+ - test/dummy/app/controllers/application_controller.rb
67
+ - test/dummy/app/controllers/musician_controller.rb
68
+ - test/dummy/app/helpers/application_helper.rb
69
+ - test/dummy/config/environments/test.rb
70
+ - test/dummy/config/environments/production.rb
71
+ - test/dummy/config/environments/development.rb
72
+ - test/dummy/config/boot.rb
73
+ - test/dummy/config/environment.rb
74
+ - test/dummy/config/initializers/secret_token.rb
75
+ - test/dummy/config/initializers/backtrace_silencers.rb
76
+ - test/dummy/config/initializers/session_store.rb
77
+ - test/dummy/config/initializers/mime_types.rb
78
+ - test/dummy/config/initializers/inflections.rb
79
+ - test/dummy/config/application.rb
80
+ - test/dummy/config/routes.rb
81
+ - test/dummy/tmp/app/cells/blog_cell.rb
82
+ - test/dummy/tmp/test/cells/blog_cell_test.rb
83
+ - test/base_methods_test.rb
84
+ - test/active_helper_test.rb
85
+ - test/support/internal_assertions_helper.rb
86
+ - test/rails/render_test.rb
87
+ - test/rails/view_test.rb
88
+ - test/rails/caching_test.rb
89
+ - test/rails/cells_test.rb
90
+ - test/rails/integration_test.rb
91
+ - test/rails/router_test.rb
92
+ - test/rails/capture_test.rb
93
+ - test/helper_test.rb
94
+ - test/cell_generator_test.rb
82
95
  has_rdoc: true
83
96
  homepage: http://cells.rubyforge.org
84
97
  licenses: []
@@ -116,25 +129,39 @@ signing_key:
116
129
  specification_version: 3
117
130
  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.
118
131
  test_files:
119
- - test/active_helper_test.rb
120
- - test/abstract_unit.rb
121
- - test/base_methods_test.rb
122
132
  - test/assertions_helper_test.rb
123
- - test/rails/router_test.rb
124
- - test/rails/view_test.rb
125
- - test/rails/capture_test.rb
126
- - test/rails/integration_test.rb
127
- - test/rails/render_test.rb
128
- - test/rails/cells_test.rb
129
- - test/rails/caching_test.rb
130
- - test/cell_generator_test.rb
131
133
  - test/test_helper.rb
132
- - test/support/internal_assertions_helper.rb
133
- - test/helper_test.rb
134
- - test/app/controllers/musician_controller.rb
135
- - test/app/controllers/cells_test_controller.rb
134
+ - test/app/cells/bad_guitarist_cell.rb
136
135
  - test/app/cells/bassist_cell.rb
137
136
  - test/app/cells/test_cell.rb
138
- - test/app/cells/bad_guitarist_cell.rb
139
- - test/app/helpers/application_helper.rb
140
137
  - test/app/helpers/helper_using_cell_helper.rb
138
+ - test/app/helpers/application_helper.rb
139
+ - test/dummy/app/controllers/application_controller.rb
140
+ - test/dummy/app/controllers/musician_controller.rb
141
+ - test/dummy/app/helpers/application_helper.rb
142
+ - test/dummy/config/environments/test.rb
143
+ - test/dummy/config/environments/production.rb
144
+ - test/dummy/config/environments/development.rb
145
+ - test/dummy/config/boot.rb
146
+ - test/dummy/config/environment.rb
147
+ - test/dummy/config/initializers/secret_token.rb
148
+ - test/dummy/config/initializers/backtrace_silencers.rb
149
+ - test/dummy/config/initializers/session_store.rb
150
+ - test/dummy/config/initializers/mime_types.rb
151
+ - test/dummy/config/initializers/inflections.rb
152
+ - test/dummy/config/application.rb
153
+ - test/dummy/config/routes.rb
154
+ - test/dummy/tmp/app/cells/blog_cell.rb
155
+ - test/dummy/tmp/test/cells/blog_cell_test.rb
156
+ - test/base_methods_test.rb
157
+ - test/active_helper_test.rb
158
+ - test/support/internal_assertions_helper.rb
159
+ - test/rails/render_test.rb
160
+ - test/rails/view_test.rb
161
+ - test/rails/caching_test.rb
162
+ - test/rails/cells_test.rb
163
+ - test/rails/integration_test.rb
164
+ - test/rails/router_test.rb
165
+ - test/rails/capture_test.rb
166
+ - test/helper_test.rb
167
+ - test/cell_generator_test.rb
@@ -1,63 +0,0 @@
1
- #require 'rails_generator/generators/components/controller/controller_generator'
2
- require 'rails/generators/named_base'
3
- module Cells
4
- module Generators
5
- class CellGenerator < ::Rails::Generators::NamedBase
6
- argument :actions, :type => :array, :default => [], :banner => "action action"
7
- check_class_collision :suffix => "Cell"
8
-
9
- def create_cell_files
10
- template 'cell.rb', File.join('app/cells', class_path, "#{file_name}_cell.rb")
11
- end
12
-
13
- hook_for :template_engine
14
- hook_for :test_framework
15
-
16
- source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
17
-
18
-
19
- #attr_reader :template_type
20
-
21
- #def initialize(runtime_args, runtime_options = {})
22
- # super
23
- # @template_type = options[:haml] ? :haml : :erb
24
- #end
25
-
26
- #def ___manifest
27
- # Directories
28
- #m.directory File.join('app/cells', class_path)
29
- #m.directory File.join('app/cells', class_path, file_name)
30
- #m.directory File.join('test/cells')
31
-
32
- # Cell
33
- #m.template 'cell.rb', File.join('app/cells', class_path, "#{file_name}_cell.rb")
34
-
35
- # View template for each action.
36
- #actions.each do |action|
37
- # path = File.join('app/cells', class_path, file_name, "#{action}.html.#{template_type}")
38
- # m.template "view.html.#{template_type}", path, :assigns => { :action => action, :path => path }
39
- #end
40
-
41
- # Functional test for the widget.
42
- #m.template 'cell_test.rb', File.join('test/cells/', "#{file_name}_cell_test.rb"), :assigns => {:states => actions}
43
- #end
44
- #end
45
-
46
- #def add_options!(opt)
47
- # opt.separator ''
48
- # opt.separator 'Options:'#
49
-
50
- # Allow option to generate HAML views instead of ERB.
51
- #opt.on('--haml',
52
- #"Generate HAML output instead of the default ERB.") do |v|
53
- # options[:haml] = v
54
- #end
55
- #end
56
-
57
- #def banner
58
- # "Usage: #{$0} cell NAME a_view another_view ... [--haml]"
59
- #end
60
-
61
- end
62
-
63
- end;end
@@ -1,4 +0,0 @@
1
- %h1
2
- <%= class_name %>#<%= action %>
3
- %p
4
- Find me in <%= path %>
@@ -1,20 +0,0 @@
1
- require 'rails/generators/erb'
2
-
3
- module Erb
4
- module Generators
5
- class CellGenerator < Base
6
- argument :actions, :type => :array, :default => [], :banner => "action action"
7
-
8
- def copy_view_files
9
- base_path = File.join("app/cells", class_path, file_name)
10
- empty_directory base_path
11
- puts base_path.inspect
12
- actions.each do |action|
13
- @action = action
14
- @path = File.join(base_path, filename_with_extensions(action))
15
- template filename_with_extensions(:view), @path
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,2 +0,0 @@
1
- <h1><%= class_name %>#<%= action %></h1>
2
- <p>Find me in <%= path %></p>
@@ -1,248 +0,0 @@
1
- ### TODO: extract that file to railties/lib/test/isolation/abstract_unit
2
-
3
- # Note:
4
- # It is important to keep this file as light as possible
5
- # the goal for tests that require this is to test booting up
6
- # rails from an empty state, so anything added here could
7
- # hide potential failures
8
- #
9
- # It is also good to know what is the bare minimum to get
10
- # Rails booted up.
11
- require 'fileutils'
12
-
13
- # TODO: Remove rubygems when possible
14
- require 'rubygems'
15
- require 'test/unit'
16
-
17
- # TODO: Remove setting this magic constant
18
- #RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..")
19
- RAILS_FRAMEWORK_ROOT = "/home/nick/projects/rails"
20
-
21
- # These files do not require any others and are needed
22
- # to run the tests
23
- require "active_support/testing/isolation"
24
- require "active_support/testing/declarative"
25
-
26
- module TestHelpers
27
- module Paths
28
- module_function
29
-
30
- TMP_PATH = File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. tmp]))
31
-
32
- def tmp_path(*args)
33
- File.join(TMP_PATH, *args)
34
- end
35
-
36
- def app_path(*args)
37
- tmp_path(*%w[app] + args)
38
- end
39
-
40
- def framework_path
41
- RAILS_FRAMEWORK_ROOT
42
- end
43
-
44
- def rails_root
45
- app_path
46
- end
47
- end
48
-
49
- module Rack
50
- def extract_body(response)
51
- "".tap do |body|
52
- response[2].each {|chunk| body << chunk }
53
- end
54
- end
55
-
56
- def get(path)
57
- @app.call(::Rack::MockRequest.env_for(path))
58
- end
59
-
60
- def assert_welcome(resp)
61
- assert_equal 200, resp[0]
62
- assert resp[1]["Content-Type"] = "text/html"
63
- assert extract_body(resp).match(/Welcome aboard/)
64
- end
65
-
66
- def assert_success(resp)
67
- assert_equal 202, resp[0]
68
- end
69
-
70
- def assert_missing(resp)
71
- assert_equal 404, resp[0]
72
- end
73
-
74
- def assert_header(key, value, resp)
75
- assert_equal value, resp[1][key.to_s]
76
- end
77
-
78
- def assert_body(expected, resp)
79
- assert_equal expected, extract_body(resp)
80
- end
81
- end
82
-
83
- module Generation
84
- def build_app(options = {})
85
- FileUtils.rm_rf(app_path)
86
- FileUtils.cp_r(tmp_path('app_template'), app_path)
87
-
88
- # Delete the initializers unless requested
89
- unless options[:initializers]
90
- Dir["#{app_path}/config/initializers/*.rb"].each do |initializer|
91
- File.delete(initializer)
92
- end
93
- end
94
-
95
- unless options[:gemfile]
96
- File.delete"#{app_path}/Gemfile"
97
- end
98
-
99
- routes = File.read("#{app_path}/config/routes.rb")
100
- if routes =~ /(\n\s*end\s*)\Z/
101
- File.open("#{app_path}/config/routes.rb", 'w') do |f|
102
- f.puts $` + "\nmatch ':controller(/:action(/:id))(.:format)'\n" + $1
103
- end
104
- end
105
-
106
- add_to_config 'config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"; config.session_store :cookie_store, :key => "_myapp_session"; config.active_support.deprecation = :log'
107
- end
108
-
109
- def make_basic_app
110
- require "rails"
111
- require "action_controller/railtie"
112
-
113
- app = Class.new(Rails::Application)
114
- app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
115
- app.config.session_store :cookie_store, :key => "_myapp_session"
116
- app.config.active_support.deprecation = :log
117
-
118
- yield app if block_given?
119
- app.initialize!
120
-
121
- app.routes.draw do
122
- match "/" => "omg#index"
123
- end
124
-
125
- require 'rack/test'
126
- extend ::Rack::Test::Methods
127
- end
128
-
129
- class Bukkit
130
- attr_reader :path
131
-
132
- def initialize(path)
133
- @path = path
134
- end
135
-
136
- def write(file, string)
137
- path = "#{@path}/#{file}"
138
- FileUtils.mkdir_p(File.dirname(path))
139
- File.open(path, "w") {|f| f.puts string }
140
- end
141
-
142
- def delete(file)
143
- File.delete("#{@path}/#{file}")
144
- end
145
- end
146
-
147
- def plugin(name, string = "")
148
- dir = "#{app_path}/vendor/plugins/#{name}"
149
- FileUtils.mkdir_p(dir)
150
-
151
- File.open("#{dir}/init.rb", 'w') do |f|
152
- f.puts "::#{name.upcase} = 'loaded'"
153
- f.puts string
154
- end
155
-
156
- Bukkit.new(dir).tap do |bukkit|
157
- yield bukkit if block_given?
158
- end
159
- end
160
-
161
- def engine(name)
162
- dir = "#{app_path}/random/#{name}"
163
- FileUtils.mkdir_p(dir)
164
-
165
- app = File.readlines("#{app_path}/config/application.rb")
166
- app.insert(2, "$:.unshift(\"#{dir}/lib\")")
167
- app.insert(3, "require #{name.inspect}")
168
-
169
- File.open("#{app_path}/config/application.rb", 'r+') do |f|
170
- f.puts app
171
- end
172
-
173
- Bukkit.new(dir).tap do |bukkit|
174
- yield bukkit if block_given?
175
- end
176
- end
177
-
178
- def script(script)
179
- Dir.chdir(app_path) do
180
- `#{Gem.ruby} #{app_path}/script/rails #{script}`
181
- end
182
- end
183
-
184
- def add_to_config(str)
185
- environment = File.read("#{app_path}/config/application.rb")
186
- if environment =~ /(\n\s*end\s*end\s*)\Z/
187
- File.open("#{app_path}/config/application.rb", 'w') do |f|
188
- f.puts $` + "\n#{str}\n" + $1
189
- end
190
- end
191
- end
192
-
193
- def app_file(path, contents)
194
- FileUtils.mkdir_p File.dirname("#{app_path}/#{path}")
195
- File.open("#{app_path}/#{path}", 'w') do |f|
196
- f.puts contents
197
- end
198
- end
199
-
200
- def controller(name, contents)
201
- app_file("app/controllers/#{name}_controller.rb", contents)
202
- end
203
-
204
- def use_frameworks(arr)
205
- to_remove = [:actionmailer,
206
- :activemodel,
207
- :activerecord,
208
- :activeresource] - arr
209
- $:.reject! {|path| path =~ %r'/(#{to_remove.join('|')})/' }
210
- end
211
-
212
- def boot_rails
213
- require File.expand_path('/home/nick/projects/rails/load_paths', __FILE__)
214
- end
215
- end
216
- end
217
-
218
- class Test::Unit::TestCase
219
- include TestHelpers::Paths
220
- include TestHelpers::Rack
221
- include TestHelpers::Generation
222
- extend ActiveSupport::Testing::Declarative
223
- end
224
-
225
- # Create a scope and build a fixture rails app
226
- Module.new do
227
- extend TestHelpers::Paths
228
- # Build a rails app
229
- if File.exist?(tmp_path)
230
- FileUtils.rm_rf(tmp_path)
231
- end
232
- FileUtils.mkdir(tmp_path)
233
-
234
- environment = File.expand_path('../../../../load_paths', __FILE__)
235
- if File.exist?("#{environment}.rb")
236
- require_environment = "-r #{environment}"
237
- end
238
-
239
- `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/bin/rails new #{tmp_path('app_template')}`
240
- File.open("#{tmp_path}/app_template/config/boot.rb", 'w') do |f|
241
- if require_environment
242
- f.puts "Dir.chdir('#{File.dirname(environment)}') do"
243
- f.puts " require '#{environment}'"
244
- f.puts "end"
245
- end
246
- f.puts "require 'rails/all'"
247
- end
248
- end
@@ -1,44 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class CellsTestController < ActionController::Base
4
- def rescue_action(e)
5
- raise e
6
- end
7
-
8
- def render_cell_state
9
- cell = params[:cell]
10
- state = params[:state]
11
-
12
- render :text => render_cell_to_string(cell, state)
13
- end
14
-
15
- def call_render_cell_with_strings
16
- static = render_cell_to_string('my_test', 'direct_output')
17
- render :text => static
18
- end
19
-
20
- def call_render_cell_with_syms
21
- static = render_cell_to_string(:my_test, :direct_output)
22
- render :text => static
23
- end
24
-
25
- def call_render_cell_with_state_view
26
- render :text => render_cell_to_string(:my_test, :view_with_instance_var)
27
- return
28
- end
29
-
30
- def render_view_with_render_cell_invocation
31
- render :file => File.join(File.dirname(__FILE__), *%w[.. views view_with_render_cell_invocation.html.erb])
32
- return
33
- end
34
-
35
- def render_just_one_view_cell
36
- static = render_cell_to_string('just_one_view', 'some_state')
37
- render :text => static
38
- end
39
-
40
- def render_state_with_link_to
41
- static = render_cell_to_string('my_test', 'state_with_link_to')
42
- render :text => static
43
- end
44
- end