Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added more tests to boost coverage to 96.4%

  • Loading branch information...
commit cde823cf77eb030834944f896fdf017e02181ad4 1 parent 30adb7e
matthew authored
View
9 lib/streamlined/helpers/window_link_helper.rb
@@ -70,15 +70,20 @@ def link_to_delete_model(item)
def link_to_next_page
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()"
end
def link_to_previous_page
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()"
end
+
+ private
+ def page_link_style
+ !@streamlined_item_pages.empty? && @streamlined_item_pages.current.previous ? "" : "display: none;"
+ end
end
View
1  tasks/rcov.rake
@@ -8,6 +8,7 @@ begin
tasks/relevance_extensions_tasks.rake
lib/streamlined/integration_tests.rb
lib/relevance/integration_test_support.rb
+ lib/relevance/controller_test_support.rb
}.join(',')
desc "Delete aggregate coverage data."
View
30 test/functional/streamlined/helpers/link_helper_test.rb
@@ -18,7 +18,10 @@ def test_guess_show_link_for
# TODO: make link JavaScript unobtrusive!
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
def test_link_to_new_model_when_quick_new_button_is_false
@@ -27,12 +30,30 @@ def test_link_to_new_model_when_quick_new_button_is_false
end
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
def test_wrap_with_link
- assert_equal '<a href="/people/show/1">foo</a>',
- @view.wrap_with_link(:action=>"show", :id=>@item.id) {"foo"}
+ result = @view.wrap_with_link("show") {"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
def test_link_toggle_element
@@ -102,5 +123,4 @@ def test_show_columns_to_export_is_false
assert_false @view.send("show_columns_to_export")
end
end
-
end
View
104 test/functional/streamlined/helpers/window_link_helper_test.rb
@@ -27,23 +27,22 @@ def setup
end
def test_guess_show_link_for
- assert_equal "(multiple)", guess_show_link_for([])
- assert_equal "(unassigned)", guess_show_link_for(nil)
- assert_equal "(unknown)", guess_show_link_for(1)
- 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))
+ with_default_route do
+ assert_equal "(multiple)", guess_show_link_for([])
+ assert_equal "(unassigned)", guess_show_link_for(nil)
+ assert_equal "(unknown)", guess_show_link_for(1)
+ 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
def test_link_to_new_model
@model_ui = flexmock(:read_only => false, :quick_new_button => true)
@model_name = "Foo"
- with_routing do |set|
- set.draw do |map|
- map.connect ':controller/:action/:id'
- assert_equal "<a href=\"#\" onclick=\"Streamlined.Windows.open_local_window_from_url" <<
- "('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
+ with_default_route do
+ assert_equal "<a href=\"#\" onclick=\"Streamlined.Windows.open_local_window_from_url" <<
+ "('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
@@ -51,13 +50,10 @@ def test_link_to_show_model
@model_ui = flexmock(:read_only => false, :quick_new_button => true)
@model_name = "Foo"
item = flexmock(:id => 123)
- with_routing do |set|
- set.draw do |map|
- map.connect ':controller/:action/:id'
- assert_equal "<a href=\"#\" onclick=\"Streamlined.Windows.open_local_window_from_url" <<
- "('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
+ with_default_route do
+ assert_equal "<a href=\"#\" onclick=\"Streamlined.Windows.open_local_window_from_url" <<
+ "('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
@@ -65,16 +61,62 @@ def test_link_to_edit_model
@model_ui = flexmock(:read_only => false, :quick_new_button => true)
@model_name = "Foo"
item = flexmock(:id => 123)
- with_routing do |set|
- set.draw do |map|
- map.connect ':controller/:action/:id'
- assert_equal "<a href=\"#\" onclick=\"Streamlined.Windows.open_local_window_from_url" <<
- "('Edit', '//foobar/edit/123', null); return false;\"><img alt=\"Edit Foo\" border=\"0\" " <<
- "src=\"//images/streamlined/edit_16.png\" title=\"Edit Foo\" /></a>", link_to_edit_model(item)
- end
+ with_default_route do
+ assert_equal "<a href=\"#\" onclick=\"Streamlined.Windows.open_local_window_from_url" <<
+ "('Edit', '//foobar/edit/123', null); return false;\"><img alt=\"Edit Foo\" border=\"0\" " <<
+ "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
+ 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
@model_ui = flexmock(:read_only => false, :quick_new_button => false)
assert_nil link_to_new_model
@@ -99,4 +141,14 @@ def test_wrap_with_link_with_array_and_empty_block
result = wrap_with_link(["foo", {:action => "bar"}]) {}
assert_select root_node(result), "a[href=foo][action=bar]", "foo"
end
+
+ private
+ def with_default_route
+ with_routing do |set|
+ set.draw do |map|
+ map.connect ':controller/:action/:id'
+ yield
+ end
+ end
+ end
end
View
1  test/unit/streamlined/column/association_test.rb
@@ -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)
end
+ private
def view_and_item_mocks(view_attrs={})
view = flexmock(:render => 'render', :controller_path => 'controller_path', :link_to_function => 'link')
item = flexmock(:id => 123)
View
0  test/unit/streamlined/helpers/link_helper_test.rb
No changes.
View
40 test/unit/streamlined/view/render_methods_test.rb
@@ -4,48 +4,38 @@
class Streamlined::View::RenderMethodsTest < Test::Unit::TestCase
include Streamlined::View::RenderMethods
- # begin stub methods
- def controller_name
- "people"
- 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
+ def test_controller_name
+ flexmock(self).should_receive(:controller => flexmock(:controller_name => "foo")).once
+ assert_equal "foo", controller_name
end
def test_convert_partial_options_for_generic
- pretend_template_exists(false)
+ setup_mocks(false)
options = {:partial=>"list", :other=>"1"}
convert_partial_options(options)
assert_equal({:layout=>false, :file=>generic_view("_list"), :other=>"1"}, options)
end
def test_convert_partial_options_and_layout_for_generic
- pretend_template_exists(false)
+ setup_mocks(false)
options = {:partial=>"list", :other=>"1", :layout=>true}
convert_partial_options(options)
assert_equal({:layout=>true, :file=>generic_view("_list"), :other=>"1"}, options)
end
def test_convert_partial_options_for_specific
- pretend_template_exists(true)
+ setup_mocks(true)
options = {:partial=>"list", :other=>"1"}
convert_partial_options(options)
assert_equal({:partial=>"list", :other=>"1"}, options)
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
Please sign in to comment.
Something went wrong with that request. Please try again.