diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/welcome_controller_test.rb | 74 | ||||
-rw-r--r-- | test/unit/helpers/application_helper_test.rb | 40 | ||||
-rw-r--r-- | test/unit/role_test.rb | 56 | ||||
-rw-r--r-- | test/unit/wiki_test.rb | 26 |
4 files changed, 72 insertions, 124 deletions
diff --git a/test/functional/welcome_controller_test.rb b/test/functional/welcome_controller_test.rb index 94a99c223..ff4655c48 100644 --- a/test/functional/welcome_controller_test.rb +++ b/test/functional/welcome_controller_test.rb @@ -106,60 +106,34 @@ class WelcomeControllerTest < ActionController::TestCase end end - context "test_api_offset_and_limit" do - context "without params" do - should "return 0, 25" do - assert_equal [0, 25], @controller.api_offset_and_limit({}) - end - end - - context "with limit" do - should "return 0, limit" do - assert_equal [0, 30], @controller.api_offset_and_limit({:limit => 30}) - end - - should "not exceed 100" do - assert_equal [0, 100], @controller.api_offset_and_limit({:limit => 120}) - end + def test_api_offset_and_limit_without_params + assert_equal [0, 25], @controller.api_offset_and_limit({}) + end - should "not be negative" do - assert_equal [0, 25], @controller.api_offset_and_limit({:limit => -10}) - end - end + def test_api_offset_and_limit_with_limit + assert_equal [0, 30], @controller.api_offset_and_limit({:limit => 30}) + assert_equal [0, 100], @controller.api_offset_and_limit({:limit => 120}) + assert_equal [0, 25], @controller.api_offset_and_limit({:limit => -10}) + end - context "with offset" do - should "return offset, 25" do - assert_equal [10, 25], @controller.api_offset_and_limit({:offset => 10}) - end + def test_api_offset_and_limit_with_offset + assert_equal [10, 25], @controller.api_offset_and_limit({:offset => 10}) + assert_equal [0, 25], @controller.api_offset_and_limit({:offset => -10}) + end - should "not be negative" do - assert_equal [0, 25], @controller.api_offset_and_limit({:offset => -10}) - end + def test_api_offset_and_limit_with_offset_and_limit + assert_equal [10, 50], @controller.api_offset_and_limit({:offset => 10, :limit => 50}) + end - context "and limit" do - should "return offset, limit" do - assert_equal [10, 50], @controller.api_offset_and_limit({:offset => 10, :limit => 50}) - end - end - end + def test_api_offset_and_limit_with_page + assert_equal [0, 25], @controller.api_offset_and_limit({:page => 1}) + assert_equal [50, 25], @controller.api_offset_and_limit({:page => 3}) + assert_equal [0, 25], @controller.api_offset_and_limit({:page => 0}) + assert_equal [0, 25], @controller.api_offset_and_limit({:page => -2}) + end - context "with page" do - should "return offset, 25" do - assert_equal [0, 25], @controller.api_offset_and_limit({:page => 1}) - assert_equal [50, 25], @controller.api_offset_and_limit({:page => 3}) - end - - should "not be negative" do - assert_equal [0, 25], @controller.api_offset_and_limit({:page => 0}) - assert_equal [0, 25], @controller.api_offset_and_limit({:page => -2}) - end - - context "and limit" do - should "return offset, limit" do - assert_equal [0, 100], @controller.api_offset_and_limit({:page => 1, :limit => 100}) - assert_equal [200, 100], @controller.api_offset_and_limit({:page => 3, :limit => 100}) - end - end - end + def test_api_offset_and_limit_with_page_and_limit + assert_equal [0, 100], @controller.api_offset_and_limit({:page => 1, :limit => 100}) + assert_equal [200, 100], @controller.api_offset_and_limit({:page => 3, :limit => 100}) end end diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 067d14dcb..ab52017ff 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -35,30 +35,24 @@ class ApplicationHelperTest < ActionView::TestCase set_tmp_attachments_directory end - context "#link_to_if_authorized" do - context "for authorized user" do - should "allow using the :controller and :action for the target link" do - User.current = User.find_by_login('admin') - - @project = Issue.first.project # Used by helper - response = link_to_if_authorized('By controller/actionr', - {:controller => 'issues', :action => 'edit', :id => Issue.first.id}) - assert_match /href/, response - end - end + test "#link_to_if_authorized for authorized user should allow using the :controller and :action for the target link" do + User.current = User.find_by_login('admin') - context "for unauthorized user" do - should "display nothing if user isn't authorized" do - User.current = User.find_by_login('dlopper') - @project = Project.find('private-child') - issue = @project.issues.first - assert !issue.visible? - - response = link_to_if_authorized('Never displayed', - {:controller => 'issues', :action => 'show', :id => issue}) - assert_nil response - end - end + @project = Issue.first.project # Used by helper + response = link_to_if_authorized('By controller/actionr', + {:controller => 'issues', :action => 'edit', :id => Issue.first.id}) + assert_match /href/, response + end + + test "#link_to_if_authorized for unauthorized user should display nothing if user isn't authorized" do + User.current = User.find_by_login('dlopper') + @project = Project.find('private-child') + issue = @project.issues.first + assert !issue.visible? + + response = link_to_if_authorized('Never displayed', + {:controller => 'issues', :action => 'show', :id => issue}) + assert_nil response end def test_auto_links diff --git a/test/unit/role_test.rb b/test/unit/role_test.rb index 45ad1ab1b..68f737d2a 100644 --- a/test/unit/role_test.rb +++ b/test/unit/role_test.rb @@ -91,55 +91,39 @@ class RoleTest < ActiveSupport::TestCase assert_equal Role.all.reject(&:builtin?).sort, Role.find_all_givable end - context "#anonymous" do - should "return the anonymous role" do + def test_anonymous_should_return_the_anonymous_role + assert_no_difference('Role.count') do role = Role.anonymous assert role.builtin? assert_equal Role::BUILTIN_ANONYMOUS, role.builtin end + end + + def test_anonymous_with_a_missing_anonymous_role_should_return_the_anonymous_role + Role.where(:builtin => Role::BUILTIN_ANONYMOUS).delete_all - context "with a missing anonymous role" do - setup do - Role.delete_all("builtin = #{Role::BUILTIN_ANONYMOUS}") - end - - should "create a new anonymous role" do - assert_difference('Role.count') do - Role.anonymous - end - end - - should "return the anonymous role" do - role = Role.anonymous - assert role.builtin? - assert_equal Role::BUILTIN_ANONYMOUS, role.builtin - end + assert_difference('Role.count') do + role = Role.anonymous + assert role.builtin? + assert_equal Role::BUILTIN_ANONYMOUS, role.builtin end end - context "#non_member" do - should "return the non-member role" do + def test_non_member_should_return_the_non_member_role + assert_no_difference('Role.count') do role = Role.non_member assert role.builtin? assert_equal Role::BUILTIN_NON_MEMBER, role.builtin end + end + + def test_non_member_with_a_missing_non_member_role_should_return_the_non_member_role + Role.where(:builtin => Role::BUILTIN_NON_MEMBER).delete_all - context "with a missing non-member role" do - setup do - Role.delete_all("builtin = #{Role::BUILTIN_NON_MEMBER}") - end - - should "create a new non-member role" do - assert_difference('Role.count') do - Role.non_member - end - end - - should "return the non-member role" do - role = Role.non_member - assert role.builtin? - assert_equal Role::BUILTIN_NON_MEMBER, role.builtin - end + assert_difference('Role.count') do + role = Role.non_member + assert role.builtin? + assert_equal Role::BUILTIN_NON_MEMBER, role.builtin end end end diff --git a/test/unit/wiki_test.rb b/test/unit/wiki_test.rb index 5e004d27c..130fde439 100644 --- a/test/unit/wiki_test.rb +++ b/test/unit/wiki_test.rb @@ -84,22 +84,18 @@ class WikiTest < ActiveSupport::TestCase assert_equal ja_test, Wiki.titleize(ja_test) end - context "#sidebar" do - setup do - @wiki = Wiki.find(1) - end - - should "return nil if undefined" do - assert_nil @wiki.sidebar - end + def test_sidebar_should_return_nil_if_undefined + @wiki = Wiki.find(1) + assert_nil @wiki.sidebar + end - should "return a WikiPage if defined" do - page = @wiki.pages.new(:title => 'Sidebar') - page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') - page.save! + def test_sidebar_should_return_a_wiki_page_if_defined + @wiki = Wiki.find(1) + page = @wiki.pages.new(:title => 'Sidebar') + page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') + page.save! - assert_kind_of WikiPage, @wiki.sidebar - assert_equal 'Sidebar', @wiki.sidebar.title - end + assert_kind_of WikiPage, @wiki.sidebar + assert_equal 'Sidebar', @wiki.sidebar.title end end |