Skip to content

Commit

Permalink
Get tests working (closes #112)
Browse files Browse the repository at this point in the history
Repaired tests:

 * test/rails/widget_generator_test.rb
 * test/rails/view_helper_test.rb
 * test/rails/rails_integration_test.rb

Tests still are omit: (none)
Proof:

 $ rake
    <...>
    153 tests, 258 assertions, 0 failures, 5 errors, 2 skips

 $ grep -r "test \"" test | wc
     22     164    1775

 $ grep -r "it \"" test | wc
    130    1056    9443

But there are errors in:

  * test/rails/rails_integration_test.rb
  • Loading branch information
kuraga committed Aug 13, 2013
1 parent 21c01a4 commit 6d7d750
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 53 deletions.
35 changes: 20 additions & 15 deletions test/rails/controller_methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ def roomies; ['mice', 'cows']; end

describe "processing an event request" do
before do
@mum = mouse_mock('mum', :eating)
@mum << @kid = mouse_mock('kid', :squeak)
@mum = mouse
@mum << mouse_mock(:kid)
@kid = @mum[:kid]

@kid.respond_to_event :doorSlam, :with => :eating, :on => 'mum'
@kid.respond_to_event :doorSlam, :with => :squeak
Expand All @@ -112,24 +113,28 @@ def squeak; render :text => 'squeak!', :update => :true; end
### DISCUSS: needed?
### FIXME: could somebody get that working?
describe "in event mode" do
# it_eventually "set the MIME type to text/javascript" do
# @controller.apotomo_root << @mum
#
# get :render_event_response, :source => :kid, :type => :doorSlam
#
# assert_equal Mime::JS, @response.content_type
# assert_equal "jQuery(\"mum\").replace(\"<div id=\\\"mum\\\">burp!<\\/div>\")\njQuery(\"kid\").update(\"squeak!\")\nsqueak();", @response.body
# end
it "set the MIME type to text/javascript" do
skip

@controller.apotomo_root << @mum

get :render_event_response, :source => :kid, :type => :doorSlam

assert_equal Mime::JS, @response.content_type
assert_equal "jQuery(\"mum\").replace(\"<div id=\\\"mum\\\">burp!<\\/div>\")\njQuery(\"kid\").update(\"squeak!\")\nsqueak();", @response.body
end
end
end

### FIXME: could somebody get that working?
describe "Routing" do
# it_eventually "generate routes to the render_event_response action" do
# assert_generates "/barn/render_event_response?type=squeak", { :controller => "barn", :action => "render_event_response", :type => "squeak" }
#
# assert_recognizes({ :controller => "apotomo", :action => "render_event_response", :type => "squeak" }, "/apotomo/render_event_response?type=squeak")
# end
it "generate routes to the render_event_response action" do
skip

assert_generates "/barn/render_event_response?type=squeak", { :controller => "barn", :action => "render_event_response", :type => "squeak" }

assert_recognizes({ :controller => "apotomo", :action => "render_event_response", :type => "squeak" }, "/apotomo/render_event_response?type=squeak")
end
end

end
38 changes: 19 additions & 19 deletions test/rails/rails_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def child
end


describe "ActionController" do
before do
# describe "ActionController" do
setup do
@controller.class.has_widgets do |root|
MumWidget.new(root, 'mum')
end
Expand All @@ -59,38 +59,38 @@ def mum
end
end

it "provide the rails view helpers in state views" do
test "provide the rails view helpers in state views" do
get 'mum', :state => :make_me_squeak
assert_select "a", "mum"
end

describe "nested widgets" do
it "render" do
# describe "nested widgets" do
test "render" do
get 'mum', :state => :child
assert_equal "/barn/render_event_response?source=kid&amp;type=click\n", @response.body
end

it "process events" do
test "process events" do
get 'render_event_response', :source => 'root', :type => :squeak
assert_equal "squeak!", @response.body
end
end
# end

it "pass the event with all params data as state-args" do
test "pass the event with all params data as state-args" do
get 'render_event_response', :source => "mum", :type => "squeak", :pitch => "high"
assert_equal "{\"source\"=>\"mum\", \"type\"=>\"squeak\", \"pitch\"=>\"high\", \"controller\"=>\"barn\", \"action\"=>\"render_event_response\"}\nsqueak!", @response.body
end

it "render updates to the parent window for an iframe request" do
test "render updates to the parent window for an iframe request" do
get 'render_event_response', :source => 'mum', :type => :sniff, :apotomo_iframe => true

assert_response :success
assert_equal 'text/html', @response.content_type
assert_equal "<html><body><script type='text/javascript' charset='utf-8'>\nvar loc = document.location;\nwith(window.parent) { setTimeout(function() { window.eval('<b>sniff sniff<\\/b>'); window.loc && loc.replace('about:blank'); }, 1) }\n</script></body></html>", @response.body
end
# end


describe "ActionView" do
# describe "ActionView" do
before do
@controller.instance_eval do
def mum
Expand All @@ -99,12 +99,12 @@ def mum
end
end

it "respond to #render_widget" do
test "respond to #render_widget" do
get :mum
assert_select "#mum", "burp!"
end

it "respond to #url_for_event" do
test "respond to #url_for_event" do
@controller.instance_eval do
def mum
render :inline => "<%= url_for_event :footsteps, :source => 'mum' %>"
Expand All @@ -115,29 +115,29 @@ def mum
assert_equal "/barn/render_event_response?source=mum&amp;type=footsteps", @response.body
end
end
end
# end
end


class IncludingApotomoSupportTest < ActiveSupport::TestCase
describe "A controller not including ControllerMethods explicitely" do
before do
# describe "A controller not including ControllerMethods explicitely" do
setup do
@class = Class.new(ActionController::Base)
@controller = @class.new
@controller.request = ActionController::TestRequest.new
end

it "respond to .has_widgets only" do
test "respond to .has_widgets only" do
assert_respond_to @class, :has_widgets
assert_not_respond_to @class, :apotomo_request_processor
end

it "mixin all methods after first use of .has_widgets" do
test "mixin all methods after first use of .has_widgets" do
@class.has_widgets do |root|
end

assert_respond_to @class, :has_widgets
assert_respond_to @controller, :apotomo_request_processor
end
end
# end
end
24 changes: 13 additions & 11 deletions test/rails/view_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'action_view/test_case'

class ViewHelperTest < Apotomo::TestCase
include Apotomo::TestCaseMethods::TestController
include ActionDispatch::Assertions::DomAssertions

# TODO: use Cell::TestCase#in_view here.
Expand All @@ -17,61 +18,62 @@ def mouse_mock(id='mum', opts={}, &block)
end


describe "A widget state view" do
after do
# describe "A widget state view" do
### DISCUSS: what is this for?
teardown do
Apotomo.js_framework = :prototype
end

### DISCUSS: needed?
### FIXME: could somebody get that working?
# it_eventually "respond to #multipart_form_to_event" do
# test "respond to #multipart_form_to_event" do
# 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&amp;source=mum&amp;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=\"&#x2713;\" /></div></form>",
# in_view(MouseWidget) do
# multipart_form_to_event(:footsteps)
# end)
# end

it "respond to #url_for_event" do
test "respond to #url_for_event" do
assert_equal("/barn/render_event_response?source=mum&amp;type=footsteps", in_view(MouseWidget) do
url_for_event(:footsteps)
end)
end

it "respond to #url_for_event with a namespaced controller" do
test "respond to #url_for_event with a namespaced controller" do
@controller = namespaced_controller
assert_equal("/farm/barn/render_event_response?source=mum&amp;type=footsteps", in_view(MouseWidget) do
url_for_event(:footsteps)
end)
end

it "respond to #widget_div" do
test "respond to #widget_div" do
assert_equal('<div id="mum">squeak!</div>', in_view(MouseWidget) do widget_div { "squeak!" } end)
end

it "respond to #widget_div with options" do
test "respond to #widget_div with options" do
assert_equal('<div class="mouse" id="kid">squeak!</div>', in_view(MouseWidget) do
widget_div(:id => 'kid', :class => "mouse") { "squeak!" }
end)
end

it "respond to #widget_id" do
test "respond to #widget_id" do
assert_equal('mum', in_view(MouseWidget){ widget_id })
end

it "respond to #render_widget" do
test "respond to #render_widget" do
mum = mouse
MouseWidget.new(mum, :kid)

assert_equal("<div id=\"kid\">burp!</div>\n", in_view(mum){ render_widget 'kid', :eat })
end

it "respond to #children" do
test "respond to #children" do
mum = mouse
MouseWidget.new(mum, :kid)

assert_equal("<div id=\"kid\">burp!</div>\n", in_view(mum) do
children.inject("") { |html, child| html += render_widget(child, :eat) }.html_safe
end)
end
end
# end
end
16 changes: 8 additions & 8 deletions test/rails/widget_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
setup :prepare_destination
tests ::Apotomo::Generators::WidgetGenerator

describe "Running rails g apotomo::widget" do
describe "Gerbil squeak snuggle" do
it "create the standard assets" do
# describe "Running rails g apotomo::widget" do
# describe "Gerbil squeak snuggle" do
test "create the standard assets" do

run_generator %w(Gerbil squeak snuggle -t test_unit)

Expand All @@ -23,7 +23,7 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
assert_file "test/widgets/gerbil_widget_test.rb", %r(widget\(:gerbil\))
end

it "create haml assets with -e haml" do
test "create haml assets with -e haml" do
run_generator %w(Gerbil squeak snuggle -e haml -t test_unit)

assert_file "app/widgets/gerbil_widget.rb", /class GerbilWidget < Apotomo::Widget/
Expand All @@ -35,7 +35,7 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
assert_file "test/widgets/gerbil_widget_test.rb"
end

it "create slim assets with -e slim" do
test "create slim assets with -e slim" do
run_generator %w(Gerbil squeak snuggle -e slim -t test_unit)

assert_file "app/widgets/gerbil_widget.rb", /class GerbilWidget < Apotomo::Widget/
Expand All @@ -47,7 +47,7 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
assert_file "test/widgets/gerbil_widget_test.rb"
end

it "work with namespaces" do
test "work with namespaces" do
run_generator %w(Gerbil::Mouse squeak -t test_unit)

assert_file "app/widgets/gerbil/mouse_widget.rb", /class Gerbil::MouseWidget < Apotomo::Widget/
Expand All @@ -56,6 +56,6 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
assert_file "test/widgets/gerbil/mouse_widget_test.rb"
end

end
end
# end
# end
end
9 changes: 9 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ def assert_not(assertion)
end
end

ActiveSupport::TestCase.class_eval do
include Apotomo::WidgetShortcuts
include Apotomo::TestCaseMethods

def assert_not(assertion)
assert !assertion
end
end

class ApotomoController < ActionController::Base
include Apotomo::Rails::ControllerMethods
include Rails.application.routes.url_helpers
Expand Down

0 comments on commit 6d7d750

Please sign in to comment.