@@ -106,60 +106,34 class WelcomeControllerTest < ActionController::TestCase | |||||
106 | end |
|
106 | end | |
107 | end |
|
107 | end | |
108 |
|
108 | |||
109 |
|
|
109 | def test_api_offset_and_limit_without_params | |
110 | context "without params" do |
|
110 | assert_equal [0, 25], @controller.api_offset_and_limit({}) | |
111 | should "return 0, 25" do |
|
111 | end | |
112 | assert_equal [0, 25], @controller.api_offset_and_limit({}) |
|
|||
113 | end |
|
|||
114 | end |
|
|||
115 |
|
||||
116 | context "with limit" do |
|
|||
117 | should "return 0, limit" do |
|
|||
118 | assert_equal [0, 30], @controller.api_offset_and_limit({:limit => 30}) |
|
|||
119 | end |
|
|||
120 |
|
||||
121 | should "not exceed 100" do |
|
|||
122 | assert_equal [0, 100], @controller.api_offset_and_limit({:limit => 120}) |
|
|||
123 | end |
|
|||
124 |
|
112 | |||
125 | should "not be negative" do |
|
113 | def test_api_offset_and_limit_with_limit | |
126 |
|
|
114 | assert_equal [0, 30], @controller.api_offset_and_limit({:limit => 30}) | |
127 | end |
|
115 | assert_equal [0, 100], @controller.api_offset_and_limit({:limit => 120}) | |
128 | end |
|
116 | assert_equal [0, 25], @controller.api_offset_and_limit({:limit => -10}) | |
|
117 | end | |||
129 |
|
118 | |||
130 | context "with offset" do |
|
119 | def test_api_offset_and_limit_with_offset | |
131 | should "return offset, 25" do |
|
120 | assert_equal [10, 25], @controller.api_offset_and_limit({:offset => 10}) | |
132 |
|
|
121 | assert_equal [0, 25], @controller.api_offset_and_limit({:offset => -10}) | |
133 |
|
|
122 | end | |
134 |
|
123 | |||
135 | should "not be negative" do |
|
124 | def test_api_offset_and_limit_with_offset_and_limit | |
136 |
|
|
125 | assert_equal [10, 50], @controller.api_offset_and_limit({:offset => 10, :limit => 50}) | |
137 |
|
|
126 | end | |
138 |
|
127 | |||
139 | context "and limit" do |
|
128 | def test_api_offset_and_limit_with_page | |
140 | should "return offset, limit" do |
|
129 | assert_equal [0, 25], @controller.api_offset_and_limit({:page => 1}) | |
141 |
|
|
130 | assert_equal [50, 25], @controller.api_offset_and_limit({:page => 3}) | |
142 | end |
|
131 | assert_equal [0, 25], @controller.api_offset_and_limit({:page => 0}) | |
143 | end |
|
132 | assert_equal [0, 25], @controller.api_offset_and_limit({:page => -2}) | |
144 |
|
|
133 | end | |
145 |
|
134 | |||
146 | context "with page" do |
|
135 | def test_api_offset_and_limit_with_page_and_limit | |
147 | should "return offset, 25" do |
|
136 | assert_equal [0, 100], @controller.api_offset_and_limit({:page => 1, :limit => 100}) | |
148 |
|
|
137 | assert_equal [200, 100], @controller.api_offset_and_limit({:page => 3, :limit => 100}) | |
149 | assert_equal [50, 25], @controller.api_offset_and_limit({:page => 3}) |
|
|||
150 | end |
|
|||
151 |
|
||||
152 | should "not be negative" do |
|
|||
153 | assert_equal [0, 25], @controller.api_offset_and_limit({:page => 0}) |
|
|||
154 | assert_equal [0, 25], @controller.api_offset_and_limit({:page => -2}) |
|
|||
155 | end |
|
|||
156 |
|
||||
157 | context "and limit" do |
|
|||
158 | should "return offset, limit" do |
|
|||
159 | assert_equal [0, 100], @controller.api_offset_and_limit({:page => 1, :limit => 100}) |
|
|||
160 | assert_equal [200, 100], @controller.api_offset_and_limit({:page => 3, :limit => 100}) |
|
|||
161 | end |
|
|||
162 | end |
|
|||
163 | end |
|
|||
164 | end |
|
138 | end | |
165 | end |
|
139 | end |
@@ -35,30 +35,24 class ApplicationHelperTest < ActionView::TestCase | |||||
35 | set_tmp_attachments_directory |
|
35 | set_tmp_attachments_directory | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | context "#link_to_if_authorized" do |
|
38 | test "#link_to_if_authorized for authorized user should allow using the :controller and :action for the target link" do | |
39 | context "for authorized user" do |
|
39 | User.current = User.find_by_login('admin') | |
40 | should "allow using the :controller and :action for the target link" do |
|
|||
41 | User.current = User.find_by_login('admin') |
|
|||
42 |
|
||||
43 | @project = Issue.first.project # Used by helper |
|
|||
44 | response = link_to_if_authorized('By controller/actionr', |
|
|||
45 | {:controller => 'issues', :action => 'edit', :id => Issue.first.id}) |
|
|||
46 | assert_match /href/, response |
|
|||
47 | end |
|
|||
48 | end |
|
|||
49 |
|
40 | |||
50 | context "for unauthorized user" do |
|
41 | @project = Issue.first.project # Used by helper | |
51 | should "display nothing if user isn't authorized" do |
|
42 | response = link_to_if_authorized('By controller/actionr', | |
52 | User.current = User.find_by_login('dlopper') |
|
43 | {:controller => 'issues', :action => 'edit', :id => Issue.first.id}) | |
53 | @project = Project.find('private-child') |
|
44 | assert_match /href/, response | |
54 | issue = @project.issues.first |
|
45 | end | |
55 | assert !issue.visible? |
|
46 | ||
56 |
|
47 | test "#link_to_if_authorized for unauthorized user should display nothing if user isn't authorized" do | ||
57 | response = link_to_if_authorized('Never displayed', |
|
48 | User.current = User.find_by_login('dlopper') | |
58 | {:controller => 'issues', :action => 'show', :id => issue}) |
|
49 | @project = Project.find('private-child') | |
59 | assert_nil response |
|
50 | issue = @project.issues.first | |
60 | end |
|
51 | assert !issue.visible? | |
61 | end |
|
52 | ||
|
53 | response = link_to_if_authorized('Never displayed', | |||
|
54 | {:controller => 'issues', :action => 'show', :id => issue}) | |||
|
55 | assert_nil response | |||
62 | end |
|
56 | end | |
63 |
|
57 | |||
64 | def test_auto_links |
|
58 | def test_auto_links |
@@ -91,55 +91,39 class RoleTest < ActiveSupport::TestCase | |||||
91 | assert_equal Role.all.reject(&:builtin?).sort, Role.find_all_givable |
|
91 | assert_equal Role.all.reject(&:builtin?).sort, Role.find_all_givable | |
92 | end |
|
92 | end | |
93 |
|
93 | |||
94 | context "#anonymous" do |
|
94 | def test_anonymous_should_return_the_anonymous_role | |
95 | should "return the anonymous role" do |
|
95 | assert_no_difference('Role.count') do | |
96 | role = Role.anonymous |
|
96 | role = Role.anonymous | |
97 | assert role.builtin? |
|
97 | assert role.builtin? | |
98 | assert_equal Role::BUILTIN_ANONYMOUS, role.builtin |
|
98 | assert_equal Role::BUILTIN_ANONYMOUS, role.builtin | |
99 | end |
|
99 | end | |
|
100 | end | |||
|
101 | ||||
|
102 | def test_anonymous_with_a_missing_anonymous_role_should_return_the_anonymous_role | |||
|
103 | Role.where(:builtin => Role::BUILTIN_ANONYMOUS).delete_all | |||
100 |
|
104 | |||
101 | context "with a missing anonymous role" do |
|
105 | assert_difference('Role.count') do | |
102 | setup do |
|
106 | role = Role.anonymous | |
103 | Role.delete_all("builtin = #{Role::BUILTIN_ANONYMOUS}") |
|
107 | assert role.builtin? | |
104 | end |
|
108 | assert_equal Role::BUILTIN_ANONYMOUS, role.builtin | |
105 |
|
||||
106 | should "create a new anonymous role" do |
|
|||
107 | assert_difference('Role.count') do |
|
|||
108 | Role.anonymous |
|
|||
109 | end |
|
|||
110 | end |
|
|||
111 |
|
||||
112 | should "return the anonymous role" do |
|
|||
113 | role = Role.anonymous |
|
|||
114 | assert role.builtin? |
|
|||
115 | assert_equal Role::BUILTIN_ANONYMOUS, role.builtin |
|
|||
116 | end |
|
|||
117 | end |
|
109 | end | |
118 | end |
|
110 | end | |
119 |
|
111 | |||
120 | context "#non_member" do |
|
112 | def test_non_member_should_return_the_non_member_role | |
121 | should "return the non-member role" do |
|
113 | assert_no_difference('Role.count') do | |
122 | role = Role.non_member |
|
114 | role = Role.non_member | |
123 | assert role.builtin? |
|
115 | assert role.builtin? | |
124 | assert_equal Role::BUILTIN_NON_MEMBER, role.builtin |
|
116 | assert_equal Role::BUILTIN_NON_MEMBER, role.builtin | |
125 | end |
|
117 | end | |
|
118 | end | |||
|
119 | ||||
|
120 | def test_non_member_with_a_missing_non_member_role_should_return_the_non_member_role | |||
|
121 | Role.where(:builtin => Role::BUILTIN_NON_MEMBER).delete_all | |||
126 |
|
122 | |||
127 | context "with a missing non-member role" do |
|
123 | assert_difference('Role.count') do | |
128 | setup do |
|
124 | role = Role.non_member | |
129 | Role.delete_all("builtin = #{Role::BUILTIN_NON_MEMBER}") |
|
125 | assert role.builtin? | |
130 | end |
|
126 | assert_equal Role::BUILTIN_NON_MEMBER, role.builtin | |
131 |
|
||||
132 | should "create a new non-member role" do |
|
|||
133 | assert_difference('Role.count') do |
|
|||
134 | Role.non_member |
|
|||
135 | end |
|
|||
136 | end |
|
|||
137 |
|
||||
138 | should "return the non-member role" do |
|
|||
139 | role = Role.non_member |
|
|||
140 | assert role.builtin? |
|
|||
141 | assert_equal Role::BUILTIN_NON_MEMBER, role.builtin |
|
|||
142 | end |
|
|||
143 | end |
|
127 | end | |
144 | end |
|
128 | end | |
145 | end |
|
129 | end |
@@ -84,22 +84,18 class WikiTest < ActiveSupport::TestCase | |||||
84 | assert_equal ja_test, Wiki.titleize(ja_test) |
|
84 | assert_equal ja_test, Wiki.titleize(ja_test) | |
85 | end |
|
85 | end | |
86 |
|
86 | |||
87 | context "#sidebar" do |
|
87 | def test_sidebar_should_return_nil_if_undefined | |
88 | setup do |
|
88 | @wiki = Wiki.find(1) | |
89 | @wiki = Wiki.find(1) |
|
89 | assert_nil @wiki.sidebar | |
90 |
|
|
90 | end | |
91 |
|
||||
92 | should "return nil if undefined" do |
|
|||
93 | assert_nil @wiki.sidebar |
|
|||
94 | end |
|
|||
95 |
|
91 | |||
96 |
|
|
92 | def test_sidebar_should_return_a_wiki_page_if_defined | |
97 | page = @wiki.pages.new(:title => 'Sidebar') |
|
93 | @wiki = Wiki.find(1) | |
98 | page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') |
|
94 | page = @wiki.pages.new(:title => 'Sidebar') | |
99 | page.save! |
|
95 | page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') | |
|
96 | page.save! | |||
100 |
|
97 | |||
101 |
|
|
98 | assert_kind_of WikiPage, @wiki.sidebar | |
102 |
|
|
99 | assert_equal 'Sidebar', @wiki.sidebar.title | |
103 | end |
|
|||
104 | end |
|
100 | end | |
105 | end |
|
101 | end |
General Comments 0
You need to be logged in to leave comments.
Login now