Skip to content

Commit

Permalink
added more tests to boost coverage to 96.4%
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew committed Nov 4, 2007
1 parent 30adb7e commit cde823c
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 58 deletions.
9 changes: 7 additions & 2 deletions lib/streamlined/helpers/window_link_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -70,15 +70,20 @@ def link_to_delete_model(item)


def link_to_next_page def link_to_next_page
link_to_function image_tag('streamlined/control-forward_16.png', link_to_function image_tag('streamlined/control-forward_16.png',
{:id => 'next_page', :alt => 'Next Page', :style => @streamlined_item_pages != [] && @streamlined_item_pages.current.next ? "" : "display: none;", :title => 'Next Page', :border => '0'}), {:id => 'next_page', :alt => 'Next Page', :style => page_link_style, :title => 'Next Page', :border => '0'}),
"Streamlined.PageOptions.nextPage()" "Streamlined.PageOptions.nextPage()"
end end


def link_to_previous_page def link_to_previous_page
link_to_function image_tag('streamlined/control-reverse_16.png', link_to_function image_tag('streamlined/control-reverse_16.png',
{:id => 'previous_page', :alt => 'Previous Page', :style => @streamlined_item_pages != [] && @streamlined_item_pages.current.previous ? "" : "display: none;", :title => 'Previous Page', :border => '0'}), {:id => 'previous_page', :alt => 'Previous Page', :style => page_link_style, :title => 'Previous Page', :border => '0'}),
"Streamlined.PageOptions.previousPage()" "Streamlined.PageOptions.previousPage()"
end end

private
def page_link_style
!@streamlined_item_pages.empty? && @streamlined_item_pages.current.previous ? "" : "display: none;"
end
end end




1 change: 1 addition & 0 deletions tasks/rcov.rake
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ begin
tasks/relevance_extensions_tasks.rake tasks/relevance_extensions_tasks.rake
lib/streamlined/integration_tests.rb lib/streamlined/integration_tests.rb
lib/relevance/integration_test_support.rb lib/relevance/integration_test_support.rb
lib/relevance/controller_test_support.rb
}.join(',') }.join(',')


desc "Delete aggregate coverage data." desc "Delete aggregate coverage data."
Expand Down
30 changes: 25 additions & 5 deletions test/functional/streamlined/helpers/link_helper_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def test_guess_show_link_for


# TODO: make link JavaScript unobtrusive! # TODO: make link JavaScript unobtrusive!
def test_link_to_new_model def test_link_to_new_model
assert_equal "<a href=\"/people/new\"><img alt=\"New Person\" border=\"0\" src=\"/images/streamlined/add_16.png\" title=\"New Person\" /></a>", @view.link_to_new_model result = @view.link_to_new_model
assert_select root_node(result), "a[href=/people/new]" do
assert_select "img[alt=New Person][border=0][src=/images/streamlined/add_16.png][title=New Person]"
end
end end


def test_link_to_new_model_when_quick_new_button_is_false def test_link_to_new_model_when_quick_new_button_is_false
Expand All @@ -27,12 +30,30 @@ def test_link_to_new_model_when_quick_new_button_is_false
end end


def test_link_to_edit_model def test_link_to_edit_model
assert_equal "<a href=\"/people/edit/1\"><img alt=\"Edit Person\" border=\"0\" src=\"/images/streamlined/edit_16.png\" title=\"Edit Person\" /></a>", @view.link_to_edit_model(people(:justin)) result = @view.link_to_edit_model(people(:justin))
assert_select root_node(result), "a[href=/people/edit/1]" do
assert_select "img[alt=Edit Person][border=0][src=/images/streamlined/edit_16.png][title=Edit Person]"
end
end end


def test_wrap_with_link def test_wrap_with_link
assert_equal '<a href="/people/show/1">foo</a>', result = @view.wrap_with_link("show") {"foo"}
@view.wrap_with_link(:action=>"show", :id=>@item.id) {"foo"} assert_select root_node(result), "a[href=show]", "foo"
end

def test_wrap_with_link_with_empty_block
result = @view.wrap_with_link("show") {}
assert_select root_node(result), "a[href=show]", "show"
end

def test_wrap_with_link_with_array
result = @view.wrap_with_link(["foo", {:action => "show", :id => "1"}]) {"bar"}
assert_select root_node(result), "a[href=foo][action=show][id=1]", "bar"
end

def test_wrap_with_link_with_array_and_empty_block
result = @view.wrap_with_link(["foo", {:action => "show", :id => "1"}]) {}
assert_select root_node(result), "a[href=foo][action=show][id=1]", "foo"
end end


def test_link_toggle_element def test_link_toggle_element
Expand Down Expand Up @@ -102,5 +123,4 @@ def test_show_columns_to_export_is_false
assert_false @view.send("show_columns_to_export") assert_false @view.send("show_columns_to_export")
end end
end end

end end
104 changes: 78 additions & 26 deletions test/functional/streamlined/helpers/window_link_helper_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,54 +27,96 @@ def setup
end end


def test_guess_show_link_for def test_guess_show_link_for
assert_equal "(multiple)", guess_show_link_for([]) with_default_route do
assert_equal "(unassigned)", guess_show_link_for(nil) assert_equal "(multiple)", guess_show_link_for([])
assert_equal "(unknown)", guess_show_link_for(1) assert_equal "(unassigned)", guess_show_link_for(nil)
assert_equal "<a href=\"//people/show/1\">1</a>", guess_show_link_for(people(:justin)) assert_equal "(unknown)", guess_show_link_for(1)
assert_equal "<a href=\"//phone_numbers/show/1\">1</a>", guess_show_link_for(phone_numbers(:number1)) assert_equal "<a href=\"//people/show/1\">1</a>", guess_show_link_for(people(:justin))
assert_equal "<a href=\"//phone_numbers/show/1\">1</a>", guess_show_link_for(phone_numbers(:number1))
end
end end


def test_link_to_new_model def test_link_to_new_model
@model_ui = flexmock(:read_only => false, :quick_new_button => true) @model_ui = flexmock(:read_only => false, :quick_new_button => true)
@model_name = "Foo" @model_name = "Foo"
with_routing do |set| with_default_route do
set.draw do |map| assert_equal "<a href=\"#\" onclick=\"Streamlined.Windows.open_local_window_from_url" <<
map.connect ':controller/:action/:id' "('New', '//foobar/new', null); return false;\"><img alt=\"New Foo\" border=\"0\" " <<
assert_equal "<a href=\"#\" onclick=\"Streamlined.Windows.open_local_window_from_url" << "src=\"//images/streamlined/add_16.png\" title=\"New Foo\" /></a>", link_to_new_model
"('New', '//foobar/new', null); return false;\"><img alt=\"New Foo\" border=\"0\" " <<
"src=\"//images/streamlined/add_16.png\" title=\"New Foo\" /></a>", link_to_new_model
end
end end
end end


def test_link_to_show_model def test_link_to_show_model
@model_ui = flexmock(:read_only => false, :quick_new_button => true) @model_ui = flexmock(:read_only => false, :quick_new_button => true)
@model_name = "Foo" @model_name = "Foo"
item = flexmock(:id => 123) item = flexmock(:id => 123)
with_routing do |set| with_default_route do
set.draw do |map| assert_equal "<a href=\"#\" onclick=\"Streamlined.Windows.open_local_window_from_url" <<
map.connect ':controller/:action/:id' "('Show', '//foobar/show/123', null); return false;\"><img alt=\"Show Foo\" border=\"0\" " <<
assert_equal "<a href=\"#\" onclick=\"Streamlined.Windows.open_local_window_from_url" << "src=\"//images/streamlined/search_16.png\" title=\"Show Foo\" /></a>", link_to_show_model(item)
"('Show', '//foobar/show/123', null); return false;\"><img alt=\"Show Foo\" border=\"0\" " <<
"src=\"//images/streamlined/search_16.png\" title=\"Show Foo\" /></a>", link_to_show_model(item)
end
end end
end end


def test_link_to_edit_model def test_link_to_edit_model
@model_ui = flexmock(:read_only => false, :quick_new_button => true) @model_ui = flexmock(:read_only => false, :quick_new_button => true)
@model_name = "Foo" @model_name = "Foo"
item = flexmock(:id => 123) item = flexmock(:id => 123)
with_routing do |set| with_default_route do
set.draw do |map| assert_equal "<a href=\"#\" onclick=\"Streamlined.Windows.open_local_window_from_url" <<
map.connect ':controller/:action/:id' "('Edit', '//foobar/edit/123', null); return false;\"><img alt=\"Edit Foo\" border=\"0\" " <<
assert_equal "<a href=\"#\" onclick=\"Streamlined.Windows.open_local_window_from_url" << "src=\"//images/streamlined/edit_16.png\" title=\"Edit Foo\" /></a>", link_to_edit_model(item)
"('Edit', '//foobar/edit/123', null); return false;\"><img alt=\"Edit Foo\" border=\"0\" " << end
"src=\"//images/streamlined/edit_16.png\" title=\"Edit Foo\" /></a>", link_to_edit_model(item) end
end
def test_link_to_delete_model
item = flexmock(:id => 123)
with_default_route do
assert_equal "<a href=\"//foobar/destroy/123\" onclick=\"if (confirm('Are you sure?')) { " <<
"var f = document.createElement('form'); f.style.display = 'none'; " <<
"this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;" <<
"var m = document.createElement('input'); m.setAttribute('type', 'hidden'); " <<
"m.setAttribute('name', '_method'); m.setAttribute('value', 'post'); " <<
"f.appendChild(m);f.submit(); };return false;\"><img alt=\"Destroy\" " <<
"border=\"0\" src=\"//images/streamlined/delete_16.png\" " <<
"title=\"Destroy\" /></a>", link_to_delete_model(item)
end
end

def test_link_to_next_page
flexmock(self).should_receive(:page_link_style).and_return("").once
with_default_route do
assert_equal "<a href=\"#\" onclick=\"Streamlined.PageOptions.nextPage(); return false;\">" <<
"<img alt=\"Next Page\" border=\"0\" id=\"next_page\" " <<
"src=\"//images/streamlined/control-forward_16.png\" style=\"\" " <<
"title=\"Next Page\" /></a>", link_to_next_page
end
end

def test_link_to_previous_page
flexmock(self).should_receive(:page_link_style).and_return("").once
with_default_route do
assert_equal "<a href=\"#\" onclick=\"Streamlined.PageOptions.previousPage(); return false;\">" <<
"<img alt=\"Previous Page\" border=\"0\" id=\"previous_page\" " <<
"src=\"//images/streamlined/control-reverse_16.png\" style=\"\" " <<
"title=\"Previous Page\" /></a>", link_to_previous_page
end end
end end


def test_page_link_style_without_pages
@streamlined_item_pages = []
assert_equal "display: none;", page_link_style
end

def test_page_link_style_with_previous_page
@streamlined_item_pages = flexmock(:empty? => false, :current => flexmock(:previous => true))
assert_equal "", page_link_style
end

def test_page_link_style_without_previous_page
@streamlined_item_pages = flexmock(:empty? => false, :current => flexmock(:previous => false))
assert_equal "display: none;", page_link_style
end

def test_link_to_new_model_when_quick_new_button_is_false def test_link_to_new_model_when_quick_new_button_is_false
@model_ui = flexmock(:read_only => false, :quick_new_button => false) @model_ui = flexmock(:read_only => false, :quick_new_button => false)
assert_nil link_to_new_model assert_nil link_to_new_model
Expand All @@ -99,4 +141,14 @@ def test_wrap_with_link_with_array_and_empty_block
result = wrap_with_link(["foo", {:action => "bar"}]) {} result = wrap_with_link(["foo", {:action => "bar"}]) {}
assert_select root_node(result), "a[href=foo][action=bar]", "foo" assert_select root_node(result), "a[href=foo][action=bar]", "foo"
end end

private
def with_default_route
with_routing do |set|
set.draw do |map|
map.connect ':controller/:action/:id'
yield
end
end
end
end end
1 change: 1 addition & 0 deletions test/unit/streamlined/column/association_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def test_render_td_edit_with_options_for_select_that_accepts_item_arg
assert_equal "select", @association.render_td_edit(view, item) assert_equal "select", @association.render_td_edit(view, item)
end end


private
def view_and_item_mocks(view_attrs={}) def view_and_item_mocks(view_attrs={})
view = flexmock(:render => 'render', :controller_path => 'controller_path', :link_to_function => 'link') view = flexmock(:render => 'render', :controller_path => 'controller_path', :link_to_function => 'link')
item = flexmock(:id => 123) item = flexmock(:id => 123)
Expand Down
Empty file.
40 changes: 15 additions & 25 deletions test/unit/streamlined/view/render_methods_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,48 +4,38 @@
class Streamlined::View::RenderMethodsTest < Test::Unit::TestCase class Streamlined::View::RenderMethodsTest < Test::Unit::TestCase
include Streamlined::View::RenderMethods include Streamlined::View::RenderMethods


# begin stub methods def test_controller_name
def controller_name flexmock(self).should_receive(:controller => flexmock(:controller_name => "foo")).once
"people" assert_equal "foo", controller_name
end

def controller_path
"people"
end

def managed_views_include?(action)
true
end

def managed_partials_include?(action)
true
end
# end stub methods

def pretend_template_exists(exists)
flexstub(self) do |stub|
stub.should_receive(:specific_template_exists?).and_return(exists)
end
end end


def test_convert_partial_options_for_generic def test_convert_partial_options_for_generic
pretend_template_exists(false) setup_mocks(false)
options = {:partial=>"list", :other=>"1"} options = {:partial=>"list", :other=>"1"}
convert_partial_options(options) convert_partial_options(options)
assert_equal({:layout=>false, :file=>generic_view("_list"), :other=>"1"}, options) assert_equal({:layout=>false, :file=>generic_view("_list"), :other=>"1"}, options)
end end


def test_convert_partial_options_and_layout_for_generic def test_convert_partial_options_and_layout_for_generic
pretend_template_exists(false) setup_mocks(false)
options = {:partial=>"list", :other=>"1", :layout=>true} options = {:partial=>"list", :other=>"1", :layout=>true}
convert_partial_options(options) convert_partial_options(options)
assert_equal({:layout=>true, :file=>generic_view("_list"), :other=>"1"}, options) assert_equal({:layout=>true, :file=>generic_view("_list"), :other=>"1"}, options)
end end


def test_convert_partial_options_for_specific def test_convert_partial_options_for_specific
pretend_template_exists(true) setup_mocks(true)
options = {:partial=>"list", :other=>"1"} options = {:partial=>"list", :other=>"1"}
convert_partial_options(options) convert_partial_options(options)
assert_equal({:partial=>"list", :other=>"1"}, options) assert_equal({:partial=>"list", :other=>"1"}, options)
end end

private
def setup_mocks(template_exists)
flexstub(self) do |s|
s.should_receive(:specific_template_exists?).and_return(template_exists)
s.should_receive(:controller_path).and_return("people")
s.should_receive(:managed_partials_include?).and_return(true)
end
end
end end

0 comments on commit cde823c

Please sign in to comment.