apotomo 0.1.4 → 1.0.0.beta1
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/Gemfile +5 -2
- data/Gemfile.lock +70 -21
- data/Rakefile +7 -7
- data/config/routes.rb +3 -3
- data/lib/apotomo/persistence.rb +21 -48
- data/lib/apotomo/rails/view_helper.rb +3 -11
- data/lib/apotomo/request_processor.rb +7 -10
- data/lib/apotomo/transition.rb +2 -2
- data/lib/apotomo/version.rb +1 -1
- data/lib/apotomo/widget.rb +12 -25
- data/lib/apotomo/widget_shortcuts.rb +1 -1
- data/lib/apotomo.rb +6 -0
- data/{generators/widget → lib/generators/apotomo}/USAGE +0 -0
- data/lib/generators/apotomo/templates/view.erb +7 -0
- data/lib/generators/apotomo/templates/view.haml +4 -0
- data/{generators/widget → lib/generators/apotomo}/templates/widget.rb +2 -1
- data/lib/generators/apotomo/templates/widget_test.rb +11 -0
- data/lib/generators/apotomo/widget_generator.rb +19 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/config/application.rb +45 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +26 -0
- data/test/dummy/config/environments/production.rb +49 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/routes.rb +59 -0
- data/test/dummy/tmp/app/cells/mouse_widget.rb +11 -0
- data/test/dummy/tmp/test/widgets/mouse_widget_test.rb +15 -0
- data/test/rails/controller_methods_test.rb +11 -14
- data/test/rails/rails_integration_test.rb +12 -11
- data/test/rails/view_helper_test.rb +4 -27
- data/test/rails/view_methods_test.rb +4 -6
- data/test/rails/widget_generator_test.rb +40 -37
- data/test/support/test_case_methods.rb +34 -7
- data/test/test_helper.rb +12 -24
- data/test/unit/container_test.rb +2 -1
- data/test/unit/event_handler_test.rb +2 -0
- data/test/unit/event_methods_test.rb +4 -3
- data/test/unit/invoke_test.rb +27 -22
- data/test/unit/onfire_integration_test.rb +2 -0
- data/test/unit/persistence_test.rb +51 -90
- data/test/unit/render_test.rb +6 -4
- data/test/unit/request_processor_test.rb +70 -48
- data/test/unit/stateful_widget_test.rb +3 -1
- data/test/unit/transition_test.rb +1 -0
- data/test/unit/widget_shortcuts_test.rb +3 -2
- data/test/unit/widget_test.rb +69 -56
- metadata +57 -34
- data/app/.jeweler_doesnt_like_empty_directories +0 -0
- data/generators/widget/templates/functional_test.rb +0 -8
- data/generators/widget/templates/view.html.erb +0 -2
- data/generators/widget/templates/view.html.haml +0 -3
- data/generators/widget/widget_generator.rb +0 -34
- data/lib/apotomo/test_methods.rb +0 -8
- data/test/support/assertions_helper.rb +0 -13
- data/test/unit/test_methods_test.rb +0 -11
@@ -0,0 +1,26 @@
|
|
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
|
+
|
20
|
+
# Print deprecation notices to the Rails logger
|
21
|
+
config.active_support.deprecation = :log
|
22
|
+
|
23
|
+
# Only use best-standards-support built into browsers
|
24
|
+
config.action_dispatch.best_standards_support = :builtin
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,49 @@
|
|
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
|
+
|
47
|
+
# Send deprecation notices to registered listeners
|
48
|
+
config.active_support.deprecation = :notify
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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
|
+
|
33
|
+
# Print deprecation notices to the stderr
|
34
|
+
config.active_support.deprecation = :stderr
|
35
|
+
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,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
|
+
Dummy::Application.config.secret_token = '50777595d4b6041cfca51636cf4e262508f96cc081757729e7123d04a5abdf9e3554e4f519b71106e41c5146a9b07b5affd2e410af1130db3a7f4538b70e2429'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Dummy::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
|
+
# Dummy::Application.config.session_store :active_record_store
|
@@ -0,0 +1,59 @@
|
|
1
|
+
Dummy::Application.routes.draw do
|
2
|
+
# The priority is based upon order of creation:
|
3
|
+
# first created -> highest priority.
|
4
|
+
|
5
|
+
# Sample of regular route:
|
6
|
+
# match 'products/:id' => 'catalog#view'
|
7
|
+
# Keep in mind you can assign values other than :controller and :action
|
8
|
+
|
9
|
+
# Sample of named route:
|
10
|
+
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
11
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
12
|
+
|
13
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
14
|
+
# resources :products
|
15
|
+
|
16
|
+
# Sample resource route with options:
|
17
|
+
# resources :products do
|
18
|
+
# member do
|
19
|
+
# get 'short'
|
20
|
+
# post 'toggle'
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# collection do
|
24
|
+
# get 'sold'
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
|
28
|
+
# Sample resource route with sub-resources:
|
29
|
+
# resources :products do
|
30
|
+
# resources :comments, :sales
|
31
|
+
# resource :seller
|
32
|
+
# end
|
33
|
+
|
34
|
+
# Sample resource route with more complex sub-resources
|
35
|
+
# resources :products do
|
36
|
+
# resources :comments
|
37
|
+
# resources :sales do
|
38
|
+
# get 'recent', :on => :collection
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
|
42
|
+
# Sample resource route within a namespace:
|
43
|
+
# namespace :admin do
|
44
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
45
|
+
# # (app/controllers/admin/products_controller.rb)
|
46
|
+
# resources :products
|
47
|
+
# end
|
48
|
+
|
49
|
+
# You can have the root of your site routed with "root"
|
50
|
+
# just remember to delete public/index.html.
|
51
|
+
# root :to => "welcome#index"
|
52
|
+
|
53
|
+
# See how all your routes lay out with "rake routes"
|
54
|
+
|
55
|
+
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
56
|
+
# Note: This route will make all actions in every controller accessible via GET requests.
|
57
|
+
match "barn/widget", :to => "barn#widget"
|
58
|
+
match ':controller(/:action(/:id(.:format)))'
|
59
|
+
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class ControllerMethodsTest < ActionController::TestCase
|
4
|
+
include Apotomo::TestCaseMethods::TestController
|
5
|
+
|
4
6
|
context "A Rails controller" do
|
5
|
-
setup do
|
6
|
-
barn_controller!
|
7
|
-
end
|
8
|
-
|
9
7
|
context "responding to #apotomo_root" do
|
10
8
|
should "initially return a root widget" do
|
11
9
|
assert_equal 1, @controller.apotomo_root.size
|
@@ -27,7 +25,7 @@ class ControllerMethodsTest < ActionController::TestCase
|
|
27
25
|
context "invoking #has_widgets" do
|
28
26
|
setup do
|
29
27
|
@controller.class.has_widgets do |root|
|
30
|
-
root <<
|
28
|
+
root << widget(:mouse_cell, 'mum')
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
@@ -42,7 +40,7 @@ class ControllerMethodsTest < ActionController::TestCase
|
|
42
40
|
|
43
41
|
should "allow multiple calls to has_widgets" do
|
44
42
|
@controller.class.has_widgets do |root|
|
45
|
-
root <<
|
43
|
+
root << widget(:mouse_cell, 'kid')
|
46
44
|
end
|
47
45
|
|
48
46
|
assert @controller.apotomo_root['mum']
|
@@ -50,12 +48,11 @@ class ControllerMethodsTest < ActionController::TestCase
|
|
50
48
|
end
|
51
49
|
|
52
50
|
should "inherit has_widgets blocks to sub-controllers" do
|
53
|
-
berry =
|
51
|
+
berry = widget(:mouse_cell, 'berry')
|
54
52
|
@sub_controller = Class.new(@controller.class) do
|
55
53
|
has_widgets { |root| root << berry }
|
56
54
|
end.new
|
57
55
|
@sub_controller.params = {}
|
58
|
-
@sub_controller.session = {}
|
59
56
|
|
60
57
|
assert @sub_controller.apotomo_root['mum']
|
61
58
|
assert @sub_controller.apotomo_root['berry']
|
@@ -63,7 +60,7 @@ class ControllerMethodsTest < ActionController::TestCase
|
|
63
60
|
|
64
61
|
should "be aliased to has_widgets" do
|
65
62
|
@controller.class.has_widgets do |root|
|
66
|
-
root <<
|
63
|
+
root << widget(:mouse_cell, 'kid')
|
67
64
|
end
|
68
65
|
|
69
66
|
assert @controller.apotomo_root['mum']
|
@@ -79,7 +76,7 @@ class ControllerMethodsTest < ActionController::TestCase
|
|
79
76
|
|
80
77
|
should "extend the widget family and remember the block with one #use_widgets call" do
|
81
78
|
@controller.use_widgets do |root|
|
82
|
-
root <<
|
79
|
+
root << widget(:mouse_cell, 'mum')
|
83
80
|
end
|
84
81
|
|
85
82
|
assert_equal 1, @controller.bound_use_widgets_blocks.size
|
@@ -87,7 +84,7 @@ class ControllerMethodsTest < ActionController::TestCase
|
|
87
84
|
end
|
88
85
|
|
89
86
|
should "add blocks only once" do
|
90
|
-
block = Proc.new {|root| root <<
|
87
|
+
block = Proc.new {|root| root << widget(:mouse_cell, 'mum')}
|
91
88
|
|
92
89
|
@controller.use_widgets &block
|
93
90
|
@controller.use_widgets &block
|
@@ -102,7 +99,7 @@ class ControllerMethodsTest < ActionController::TestCase
|
|
102
99
|
root << @mum
|
103
100
|
end
|
104
101
|
@controller.use_widgets do |root|
|
105
|
-
root <<
|
102
|
+
root << widget(:mouse_cell, 'pet')
|
106
103
|
end
|
107
104
|
|
108
105
|
assert_equal 2, @controller.bound_use_widgets_blocks.size
|
@@ -112,7 +109,7 @@ class ControllerMethodsTest < ActionController::TestCase
|
|
112
109
|
|
113
110
|
context "invoking #url_for_event" do
|
114
111
|
should "compute an url for any widget" do
|
115
|
-
assert_equal "/barn/render_event_response?source=mouse&type=footsteps
|
112
|
+
assert_equal "/barn/render_event_response?source=mouse&volume=9&type=footsteps", @controller.url_for_event(:footsteps, :source => :mouse, :volume => 9)
|
116
113
|
end
|
117
114
|
end
|
118
115
|
|
@@ -131,7 +128,7 @@ class ControllerMethodsTest < ActionController::TestCase
|
|
131
128
|
|
132
129
|
should "render the widget" do
|
133
130
|
@controller.apotomo_root << @mum
|
134
|
-
assert_equal
|
131
|
+
assert_equal "<div id=\"mum\"><snuggle></snuggle></div>\n", @controller.render_widget('mum')
|
135
132
|
end
|
136
133
|
end
|
137
134
|
|
@@ -3,18 +3,20 @@ require 'test_helper'
|
|
3
3
|
class RailsIntegrationTest < ActionController::TestCase
|
4
4
|
def simulate_request!
|
5
5
|
@controller.instance_eval { @apotomo_request_processor = nil }
|
6
|
-
|
6
|
+
|
7
|
+
### FIXME: @controller.session = Marshal.load(Marshal.dump(@controller.session))
|
7
8
|
end
|
8
9
|
|
10
|
+
include Apotomo::TestCaseMethods::TestController
|
11
|
+
|
9
12
|
context "A Rails controller" do
|
10
13
|
setup do
|
11
|
-
@
|
12
|
-
@
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@mum.instance_eval{ def snuggle; render; end }
|
14
|
+
@mum = MouseCell.new(parent_controller, 'mum', :snuggle)
|
15
|
+
@mum.class.class_eval do
|
16
|
+
responds_to_event :squeak, :with => :snuggle
|
17
|
+
|
18
|
+
def snuggle; render; end
|
19
|
+
end
|
18
20
|
|
19
21
|
@controller.instance_variable_set(:@mum, @mum)
|
20
22
|
@controller.instance_eval do
|
@@ -61,7 +63,7 @@ class RailsIntegrationTest < ActionController::TestCase
|
|
61
63
|
end
|
62
64
|
|
63
65
|
get 'widget'
|
64
|
-
assert_select "a", "
|
66
|
+
assert_select "a", "mum"
|
65
67
|
end
|
66
68
|
|
67
69
|
should "contain a freshly flushed tree when ?flush_widgets=1 is set" do
|
@@ -85,7 +87,6 @@ class RailsIntegrationTest < ActionController::TestCase
|
|
85
87
|
should "render updates to the parent window for an iframe request" do
|
86
88
|
get 'widget'
|
87
89
|
assert_response :success
|
88
|
-
@controller.apotomo_root['mum'].respond_to_event :squeak, :with => :snuggle
|
89
90
|
|
90
91
|
simulate_request!
|
91
92
|
|
@@ -93,7 +94,7 @@ class RailsIntegrationTest < ActionController::TestCase
|
|
93
94
|
|
94
95
|
assert_response :success
|
95
96
|
assert_equal 'text/html', @response.content_type
|
96
|
-
assert_equal "<html><body><script type='text/javascript' charset='utf-8'>\nvar loc = document.location;\nwith(window.parent) { setTimeout(function() { window.eval('<div id=\\\"mum\\\"><snuggle><\\/snuggle><\\/div
|
97
|
+
assert_equal "<html><body><script type='text/javascript' charset='utf-8'>\nvar loc = document.location;\nwith(window.parent) { setTimeout(function() { window.eval('<div id=\\\"mum\\\"><snuggle><\\/snuggle><\\/div>\\n'); window.loc && loc.replace('about:blank'); }, 1) }\n</script></body></html>", @response.body
|
97
98
|
end
|
98
99
|
end
|
99
100
|
end
|
@@ -2,12 +2,12 @@ require 'test_helper'
|
|
2
2
|
require 'action_view/test_case'
|
3
3
|
|
4
4
|
class ViewHelperTest < ActionView::TestCase
|
5
|
+
include Apotomo::TestCaseMethods::TestController
|
6
|
+
|
5
7
|
tests Apotomo::Rails::ViewHelper
|
6
8
|
|
7
9
|
context "A widget state view" do
|
8
10
|
setup do
|
9
|
-
barn_controller!
|
10
|
-
|
11
11
|
@cell = mouse_mock('mum')
|
12
12
|
end
|
13
13
|
|
@@ -15,23 +15,14 @@ class ViewHelperTest < ActionView::TestCase
|
|
15
15
|
Apotomo.js_framework = :prototype
|
16
16
|
end
|
17
17
|
|
18
|
-
should "respond to #link_to_event" do
|
19
|
-
assert_dom_equal "<a href=\"#\" onclick=\"new Ajax.Request('/barn/render_event_response?source=mum&type=footsteps', {asynchronous:true, evalScripts:true}); return false;\">Walk!</a>",
|
20
|
-
link_to_event("Walk!", :footsteps)
|
21
|
-
end
|
22
|
-
|
23
|
-
should "respond to #form_to_event" do
|
24
|
-
assert_dom_equal "<form onsubmit=\"new Ajax.Request('/barn/render_event_response?source=mum&type=footsteps', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\" method=\"post\" action=\"/barn/render_event_response?source=mum&type=footsteps\">",
|
25
|
-
form_to_event(:footsteps)
|
26
|
-
end
|
27
18
|
|
28
19
|
should "respond to #multipart_form_to_event" do
|
29
|
-
assert_dom_equal "<iframe
|
20
|
+
assert_dom_equal "<iframe id=\"apotomo_iframe\" name=\"apotomo_iframe\" style=\"display: none;\"></iframe><form accept-charset=\"UTF-8\" action=\"/barn/render_event_response?apotomo_iframe=true&source=mum&type=footsteps\" enctype=\"multipart/form-data\" method=\"post\" target=\"apotomo_iframe\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"✓\" /></div></form>",
|
30
21
|
multipart_form_to_event(:footsteps)
|
31
22
|
end
|
32
23
|
|
33
24
|
should "render multipart form if :multipart => true" do
|
34
|
-
assert_dom_equal "<iframe
|
25
|
+
assert_dom_equal "<iframe id=\"apotomo_iframe\" name=\"apotomo_iframe\" style=\"display: none;\"></iframe><form accept-charset=\"UTF-8\" action=\"/barn/render_event_response?apotomo_iframe=true&source=mum&type=footsteps\" enctype=\"multipart/form-data\" method=\"post\" target=\"apotomo_iframe\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"✓\" /></div></form>",
|
35
26
|
form_to_event(:footsteps, :multipart => true)
|
36
27
|
end
|
37
28
|
|
@@ -81,18 +72,4 @@ class ViewHelperTest < ActionView::TestCase
|
|
81
72
|
end
|
82
73
|
end
|
83
74
|
end
|
84
|
-
|
85
|
-
context "A widget including ViewHelper" do
|
86
|
-
setup do
|
87
|
-
barn_controller!
|
88
|
-
@mum = mouse_mock
|
89
|
-
@mum.class_eval do
|
90
|
-
include Apotomo::Rails::ViewHelper
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
should "respond to url_for_event" do
|
95
|
-
@mum.url_for_event(:bla)
|
96
|
-
end
|
97
|
-
end
|
98
75
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
|
2
|
+
|
3
3
|
class ViewMethodsTest < ActionController::TestCase
|
4
|
+
include Apotomo::TestCaseMethods::TestController
|
5
|
+
|
4
6
|
context "A Rails controller view" do
|
5
7
|
setup do
|
6
|
-
@controller = ApotomoController.new
|
7
|
-
@controller.extend Apotomo::Rails::ControllerMethods
|
8
|
-
@controller.session = {}
|
9
|
-
|
10
8
|
@controller.instance_variable_set(:@mum, mouse_mock('mum', 'snuggle') {def snuggle; render; end})
|
11
9
|
@controller.instance_eval do
|
12
10
|
def widget
|
@@ -34,7 +32,7 @@ class ViewMethodsTest < ActionController::TestCase
|
|
34
32
|
end
|
35
33
|
|
36
34
|
get :widget
|
37
|
-
assert_equal "/
|
35
|
+
assert_equal "/barn/render_event_response?source=mum&type=footsteps", @response.body
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
@@ -1,47 +1,50 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require '
|
3
|
-
require 'rails_generator/scripts/generate'
|
2
|
+
require 'generators/apotomo/widget_generator'
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
teardown do
|
15
|
-
FileUtils.rm_r(fake_rails_root)
|
16
|
-
end
|
17
|
-
|
18
|
-
context "MouseWidget squeak snuggle" do
|
4
|
+
class WidgetGeneratorTest < Rails::Generators::TestCase
|
5
|
+
destination File.join(Rails.root, "tmp")
|
6
|
+
setup :prepare_destination
|
7
|
+
tests ::Apotomo::Generators::WidgetGenerator
|
8
|
+
|
9
|
+
context "Running rails g apotomo::widget" do
|
10
|
+
context "Mouse squeak snuggle" do
|
19
11
|
should "create the standard assets" do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
12
|
+
|
13
|
+
run_generator %w(MouseWidget squeak snuggle)
|
14
|
+
|
15
|
+
assert_file "app/cells/mouse_widget.rb", /class MouseWidget < Apotomo::Widget/
|
16
|
+
assert_file "app/cells/mouse_widget.rb", /def snuggle/
|
17
|
+
assert_file "app/cells/mouse_widget.rb", /def squeak/
|
18
|
+
assert_file "app/cells/mouse_widget/snuggle.html.erb", %r(app/cells/mouse_widget/snuggle\.html\.erb)
|
19
|
+
assert_file "app/cells/mouse_widget/snuggle.html.erb", %r(<p>)
|
20
|
+
assert_file "app/cells/mouse_widget/squeak.html.erb", %r(app/cells/mouse_widget/squeak\.html\.erb)
|
21
|
+
|
22
|
+
assert_file "test/widgets/mouse_widget_test.rb", %r(class MouseWidgetTest < Apotomo::TestCase)
|
26
23
|
end
|
27
24
|
|
28
25
|
should "create haml assets with --haml" do
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
run_generator %w(MouseWidget squeak snuggle --haml)
|
27
|
+
|
28
|
+
assert_file "app/cells/mouse_widget.rb", /class MouseWidget < Apotomo::Widget/
|
29
|
+
assert_file "app/cells/mouse_widget.rb", /def snuggle/
|
30
|
+
assert_file "app/cells/mouse_widget.rb", /def squeak/
|
31
|
+
assert_file "app/cells/mouse_widget/snuggle.html.haml", %r(app/cells/mouse_widget/snuggle\.html\.haml)
|
32
|
+
assert_file "app/cells/mouse_widget/snuggle.html.haml", %r(%p)
|
33
|
+
assert_file "app/cells/mouse_widget/squeak.html.haml", %r(app/cells/mouse_widget/squeak\.html\.haml)
|
34
|
+
assert_file "test/widgets/mouse_widget_test.rb"
|
35
|
+
end
|
36
|
+
|
37
|
+
should "create haml assets with -t haml" do
|
38
|
+
run_generator %w(MouseWidget snuggle squeak -t haml)
|
39
|
+
|
40
|
+
assert_file "app/cells/mouse_widget.rb", /class MouseWidget < Apotomo::Widget/
|
41
|
+
assert_file "app/cells/mouse_widget.rb", /def snuggle/
|
42
|
+
assert_file "app/cells/mouse_widget.rb", /def squeak/
|
43
|
+
assert_file "app/cells/mouse_widget/snuggle.html.haml", %r(app/cells/mouse_widget/snuggle\.html\.haml)
|
44
|
+
assert_file "app/cells/mouse_widget/snuggle.html.haml", %r(%p)
|
45
|
+
assert_file "app/cells/mouse_widget/squeak.html.haml", %r(app/cells/mouse_widget/squeak\.html\.haml)
|
46
|
+
assert_file "test/widgets/mouse_widget_test.rb"
|
35
47
|
end
|
36
48
|
end
|
37
49
|
end
|
38
|
-
|
39
|
-
private
|
40
|
-
def fake_rails_root
|
41
|
-
File.join(File.dirname(__FILE__), 'rails_root')
|
42
|
-
end
|
43
|
-
|
44
|
-
def file_list
|
45
|
-
Dir.glob(File.join(fake_rails_root, "**/*"))
|
46
|
-
end
|
47
50
|
end
|
@@ -2,10 +2,8 @@ module Apotomo
|
|
2
2
|
module TestCaseMethods
|
3
3
|
# Provides a ready-to-use mouse widget instance.
|
4
4
|
def mouse_mock(id='mouse', start_state=:eating, opts={}, &block)
|
5
|
-
|
6
|
-
mouse = MouseCell.new(id, start_state, opts)
|
5
|
+
mouse = MouseCell.new(parent_controller, id, start_state, opts)
|
7
6
|
mouse.instance_eval &block if block_given?
|
8
|
-
mouse.controller = @controller
|
9
7
|
mouse
|
10
8
|
end
|
11
9
|
|
@@ -48,15 +46,15 @@ module Apotomo
|
|
48
46
|
@controller.class.instance_eval { include Apotomo::Rails::ControllerMethods }
|
49
47
|
@controller.extend ActionController::UrlWriter
|
50
48
|
@controller.params = {}
|
51
|
-
@controller.session = {}
|
49
|
+
### FIXME: @controller.session = {}
|
52
50
|
end
|
53
51
|
|
54
52
|
def hibernate_widget(widget, session = {})
|
55
|
-
|
53
|
+
Apotomo::StatefulWidget.freeze_for(session, widget)
|
56
54
|
|
57
55
|
session = Marshal.load(Marshal.dump(session))
|
58
56
|
|
59
|
-
Apotomo::StatefulWidget.
|
57
|
+
Apotomo::StatefulWidget.thaw_for(@controller, session, )
|
60
58
|
end
|
61
59
|
|
62
60
|
def hibernate(widget, session = {})
|
@@ -64,5 +62,34 @@ module Apotomo
|
|
64
62
|
session = Marshal.load(Marshal.dump(session))
|
65
63
|
Apotomo::StatefulWidget.thaw_for(session, widget('apotomo/widget', 'root'))
|
66
64
|
end
|
65
|
+
|
66
|
+
module TestController
|
67
|
+
def setup
|
68
|
+
barn_controller!
|
69
|
+
end
|
70
|
+
|
71
|
+
# Creates a mock controller instance. Currently, each widget needs a parent controller instance due to some
|
72
|
+
# sucky dependency in cells.
|
73
|
+
def barn_controller!
|
74
|
+
@controller = Class.new(ActionController::Base) do
|
75
|
+
def initialize
|
76
|
+
extend ActionController::UrlWriter
|
77
|
+
self.params = {}
|
78
|
+
self.request = ActionController::TestRequest.new
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.name; "BarnController"; end
|
82
|
+
|
83
|
+
def self.default_url_options; {:controller => :barn}; end
|
84
|
+
include Apotomo::Rails::ControllerMethods
|
85
|
+
end.new
|
86
|
+
### FIXME: @controller.session = {}
|
87
|
+
end
|
88
|
+
|
89
|
+
def parent_controller
|
90
|
+
@controller
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
67
94
|
end
|
68
|
-
end
|
95
|
+
end
|