Revision 1297:0a574315af3e .svn/pristine/e1
| .svn/pristine/e1/e13988310e901a19cc8571a0b64f670e6e88c02b.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2012 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
require File.expand_path('../../../test_helper', __FILE__)
|
|
| 19 |
|
|
| 20 |
class ApiTest::TimeEntriesTest < ActionController::IntegrationTest |
|
| 21 |
fixtures :projects, :trackers, :issue_statuses, :issues, |
|
| 22 |
:enumerations, :users, :issue_categories, |
|
| 23 |
:projects_trackers, |
|
| 24 |
:roles, |
|
| 25 |
:member_roles, |
|
| 26 |
:members, |
|
| 27 |
:enabled_modules, |
|
| 28 |
:workflows, |
|
| 29 |
:time_entries |
|
| 30 |
|
|
| 31 |
def setup |
|
| 32 |
Setting.rest_api_enabled = '1' |
|
| 33 |
end |
|
| 34 |
|
|
| 35 |
context "GET /time_entries.xml" do |
|
| 36 |
should "return time entries" do |
|
| 37 |
get '/time_entries.xml', {}, credentials('jsmith')
|
|
| 38 |
assert_response :success |
|
| 39 |
assert_equal 'application/xml', @response.content_type |
|
| 40 |
assert_tag :tag => 'time_entries', |
|
| 41 |
:child => {:tag => 'time_entry', :child => {:tag => 'id', :content => '2'}}
|
|
| 42 |
end |
|
| 43 |
|
|
| 44 |
context "with limit" do |
|
| 45 |
should "return limited results" do |
|
| 46 |
get '/time_entries.xml?limit=2', {}, credentials('jsmith')
|
|
| 47 |
assert_response :success |
|
| 48 |
assert_equal 'application/xml', @response.content_type |
|
| 49 |
assert_tag :tag => 'time_entries', |
|
| 50 |
:children => {:count => 2}
|
|
| 51 |
end |
|
| 52 |
end |
|
| 53 |
end |
|
| 54 |
|
|
| 55 |
context "GET /time_entries/2.xml" do |
|
| 56 |
should "return requested time entry" do |
|
| 57 |
get '/time_entries/2.xml', {}, credentials('jsmith')
|
|
| 58 |
assert_response :success |
|
| 59 |
assert_equal 'application/xml', @response.content_type |
|
| 60 |
assert_tag :tag => 'time_entry', |
|
| 61 |
:child => {:tag => 'id', :content => '2'}
|
|
| 62 |
end |
|
| 63 |
end |
|
| 64 |
|
|
| 65 |
context "POST /time_entries.xml" do |
|
| 66 |
context "with issue_id" do |
|
| 67 |
should "return create time entry" do |
|
| 68 |
assert_difference 'TimeEntry.count' do |
|
| 69 |
post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith')
|
|
| 70 |
end |
|
| 71 |
assert_response :created |
|
| 72 |
assert_equal 'application/xml', @response.content_type |
|
| 73 |
|
|
| 74 |
entry = TimeEntry.first(:order => 'id DESC') |
|
| 75 |
assert_equal 'jsmith', entry.user.login |
|
| 76 |
assert_equal Issue.find(1), entry.issue |
|
| 77 |
assert_equal Project.find(1), entry.project |
|
| 78 |
assert_equal Date.parse('2010-12-02'), entry.spent_on
|
|
| 79 |
assert_equal 3.5, entry.hours |
|
| 80 |
assert_equal TimeEntryActivity.find(11), entry.activity |
|
| 81 |
end |
|
| 82 |
|
|
| 83 |
should "accept custom fields" do |
|
| 84 |
field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'string') |
|
| 85 |
|
|
| 86 |
assert_difference 'TimeEntry.count' do |
|
| 87 |
post '/time_entries.xml', {:time_entry => {
|
|
| 88 |
:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11', :custom_fields => [{:id => field.id.to_s, :value => 'accepted'}]
|
|
| 89 |
}}, credentials('jsmith')
|
|
| 90 |
end |
|
| 91 |
assert_response :created |
|
| 92 |
assert_equal 'application/xml', @response.content_type |
|
| 93 |
|
|
| 94 |
entry = TimeEntry.first(:order => 'id DESC') |
|
| 95 |
assert_equal 'accepted', entry.custom_field_value(field) |
|
| 96 |
end |
|
| 97 |
end |
|
| 98 |
|
|
| 99 |
context "with project_id" do |
|
| 100 |
should "return create time entry" do |
|
| 101 |
assert_difference 'TimeEntry.count' do |
|
| 102 |
post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith')
|
|
| 103 |
end |
|
| 104 |
assert_response :created |
|
| 105 |
assert_equal 'application/xml', @response.content_type |
|
| 106 |
|
|
| 107 |
entry = TimeEntry.first(:order => 'id DESC') |
|
| 108 |
assert_equal 'jsmith', entry.user.login |
|
| 109 |
assert_nil entry.issue |
|
| 110 |
assert_equal Project.find(1), entry.project |
|
| 111 |
assert_equal Date.parse('2010-12-02'), entry.spent_on
|
|
| 112 |
assert_equal 3.5, entry.hours |
|
| 113 |
assert_equal TimeEntryActivity.find(11), entry.activity |
|
| 114 |
end |
|
| 115 |
end |
|
| 116 |
|
|
| 117 |
context "with invalid parameters" do |
|
| 118 |
should "return errors" do |
|
| 119 |
assert_no_difference 'TimeEntry.count' do |
|
| 120 |
post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, credentials('jsmith')
|
|
| 121 |
end |
|
| 122 |
assert_response :unprocessable_entity |
|
| 123 |
assert_equal 'application/xml', @response.content_type |
|
| 124 |
|
|
| 125 |
assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"}
|
|
| 126 |
end |
|
| 127 |
end |
|
| 128 |
end |
|
| 129 |
|
|
| 130 |
context "PUT /time_entries/2.xml" do |
|
| 131 |
context "with valid parameters" do |
|
| 132 |
should "update time entry" do |
|
| 133 |
assert_no_difference 'TimeEntry.count' do |
|
| 134 |
put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith')
|
|
| 135 |
end |
|
| 136 |
assert_response :ok |
|
| 137 |
assert_equal '', @response.body |
|
| 138 |
assert_equal 'API Update', TimeEntry.find(2).comments |
|
| 139 |
end |
|
| 140 |
end |
|
| 141 |
|
|
| 142 |
context "with invalid parameters" do |
|
| 143 |
should "return errors" do |
|
| 144 |
assert_no_difference 'TimeEntry.count' do |
|
| 145 |
put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, credentials('jsmith')
|
|
| 146 |
end |
|
| 147 |
assert_response :unprocessable_entity |
|
| 148 |
assert_equal 'application/xml', @response.content_type |
|
| 149 |
|
|
| 150 |
assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"}
|
|
| 151 |
end |
|
| 152 |
end |
|
| 153 |
end |
|
| 154 |
|
|
| 155 |
context "DELETE /time_entries/2.xml" do |
|
| 156 |
should "destroy time entry" do |
|
| 157 |
assert_difference 'TimeEntry.count', -1 do |
|
| 158 |
delete '/time_entries/2.xml', {}, credentials('jsmith')
|
|
| 159 |
end |
|
| 160 |
assert_response :ok |
|
| 161 |
assert_equal '', @response.body |
|
| 162 |
assert_nil TimeEntry.find_by_id(2) |
|
| 163 |
end |
|
| 164 |
end |
|
| 165 |
end |
|
| .svn/pristine/e1/e15233fcde4e3b590807c2f76281829a10e3c2ae.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2012 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
require File.expand_path('../../test_helper', __FILE__)
|
|
| 19 |
|
|
| 20 |
class CustomFieldsControllerTest < ActionController::TestCase |
|
| 21 |
fixtures :custom_fields, :custom_values, :trackers, :users |
|
| 22 |
|
|
| 23 |
def setup |
|
| 24 |
@request.session[:user_id] = 1 |
|
| 25 |
end |
|
| 26 |
|
|
| 27 |
def test_index |
|
| 28 |
get :index |
|
| 29 |
assert_response :success |
|
| 30 |
assert_template 'index' |
|
| 31 |
end |
|
| 32 |
|
|
| 33 |
def test_new |
|
| 34 |
custom_field_classes.each do |klass| |
|
| 35 |
get :new, :type => klass.name |
|
| 36 |
assert_response :success |
|
| 37 |
assert_template 'new' |
|
| 38 |
assert_kind_of klass, assigns(:custom_field) |
|
| 39 |
assert_select 'form#custom_field_form' do |
|
| 40 |
assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]' |
|
| 41 |
assert_select 'input[type=hidden][name=type][value=?]', klass.name |
|
| 42 |
end |
|
| 43 |
end |
|
| 44 |
end |
|
| 45 |
|
|
| 46 |
def test_new_issue_custom_field |
|
| 47 |
get :new, :type => 'IssueCustomField' |
|
| 48 |
assert_response :success |
|
| 49 |
assert_template 'new' |
|
| 50 |
assert_select 'form#custom_field_form' do |
|
| 51 |
assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]' do |
|
| 52 |
assert_select 'option[value=user]', :text => 'User' |
|
| 53 |
assert_select 'option[value=version]', :text => 'Version' |
|
| 54 |
end |
|
| 55 |
assert_select 'input[type=hidden][name=type][value=IssueCustomField]' |
|
| 56 |
end |
|
| 57 |
end |
|
| 58 |
|
|
| 59 |
def test_new_js |
|
| 60 |
get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'list'}, :format => 'js'
|
|
| 61 |
assert_response :success |
|
| 62 |
assert_template 'new' |
|
| 63 |
assert_equal 'text/javascript', response.content_type |
|
| 64 |
|
|
| 65 |
field = assigns(:custom_field) |
|
| 66 |
assert_equal 'list', field.field_format |
|
| 67 |
end |
|
| 68 |
|
|
| 69 |
def test_new_with_invalid_custom_field_class_should_render_404 |
|
| 70 |
get :new, :type => 'UnknownCustomField' |
|
| 71 |
assert_response 404 |
|
| 72 |
end |
|
| 73 |
|
|
| 74 |
def test_create_list_custom_field |
|
| 75 |
assert_difference 'CustomField.count' do |
|
| 76 |
post :create, :type => "IssueCustomField", |
|
| 77 |
:custom_field => {:name => "test_post_new_list",
|
|
| 78 |
:default_value => "", |
|
| 79 |
:min_length => "0", |
|
| 80 |
:searchable => "0", |
|
| 81 |
:regexp => "", |
|
| 82 |
:is_for_all => "1", |
|
| 83 |
:possible_values => "0.1\n0.2\n", |
|
| 84 |
:max_length => "0", |
|
| 85 |
:is_filter => "0", |
|
| 86 |
:is_required =>"0", |
|
| 87 |
:field_format => "list", |
|
| 88 |
:tracker_ids => ["1", ""]} |
|
| 89 |
end |
|
| 90 |
assert_redirected_to '/custom_fields?tab=IssueCustomField' |
|
| 91 |
field = IssueCustomField.find_by_name('test_post_new_list')
|
|
| 92 |
assert_not_nil field |
|
| 93 |
assert_equal ["0.1", "0.2"], field.possible_values |
|
| 94 |
assert_equal 1, field.trackers.size |
|
| 95 |
end |
|
| 96 |
|
|
| 97 |
def test_create_with_failure |
|
| 98 |
assert_no_difference 'CustomField.count' do |
|
| 99 |
post :create, :type => "IssueCustomField", :custom_field => {:name => ''}
|
|
| 100 |
end |
|
| 101 |
assert_response :success |
|
| 102 |
assert_template 'new' |
|
| 103 |
end |
|
| 104 |
|
|
| 105 |
def test_edit |
|
| 106 |
get :edit, :id => 1 |
|
| 107 |
assert_response :success |
|
| 108 |
assert_template 'edit' |
|
| 109 |
assert_tag 'input', :attributes => {:name => 'custom_field[name]', :value => 'Database'}
|
|
| 110 |
end |
|
| 111 |
|
|
| 112 |
def test_edit_invalid_custom_field_should_render_404 |
|
| 113 |
get :edit, :id => 99 |
|
| 114 |
assert_response 404 |
|
| 115 |
end |
|
| 116 |
|
|
| 117 |
def test_update |
|
| 118 |
put :update, :id => 1, :custom_field => {:name => 'New name'}
|
|
| 119 |
assert_redirected_to '/custom_fields?tab=IssueCustomField' |
|
| 120 |
|
|
| 121 |
field = CustomField.find(1) |
|
| 122 |
assert_equal 'New name', field.name |
|
| 123 |
end |
|
| 124 |
|
|
| 125 |
def test_update_with_failure |
|
| 126 |
put :update, :id => 1, :custom_field => {:name => ''}
|
|
| 127 |
assert_response :success |
|
| 128 |
assert_template 'edit' |
|
| 129 |
end |
|
| 130 |
|
|
| 131 |
def test_destroy |
|
| 132 |
custom_values_count = CustomValue.count(:conditions => {:custom_field_id => 1})
|
|
| 133 |
assert custom_values_count > 0 |
|
| 134 |
|
|
| 135 |
assert_difference 'CustomField.count', -1 do |
|
| 136 |
assert_difference 'CustomValue.count', - custom_values_count do |
|
| 137 |
delete :destroy, :id => 1 |
|
| 138 |
end |
|
| 139 |
end |
|
| 140 |
|
|
| 141 |
assert_redirected_to '/custom_fields?tab=IssueCustomField' |
|
| 142 |
assert_nil CustomField.find_by_id(1) |
|
| 143 |
assert_nil CustomValue.find_by_custom_field_id(1) |
|
| 144 |
end |
|
| 145 |
|
|
| 146 |
def custom_field_classes |
|
| 147 |
files = Dir.glob(File.join(Rails.root, 'app/models/*_custom_field.rb')).map {|f| File.basename(f).sub(/\.rb$/, '') }
|
|
| 148 |
classes = files.map(&:classify).map(&:constantize) |
|
| 149 |
assert classes.size > 0 |
|
| 150 |
classes |
|
| 151 |
end |
|
| 152 |
end |
|
| .svn/pristine/e1/e154bc657c3fcf2d4faf4bb0c3ce33fba976be07.svn-base | ||
|---|---|---|
| 1 |
<h2><%= l(:label_settings) %>: <%=h @plugin.name %></h2> |
|
| 2 |
|
|
| 3 |
<div id="settings"> |
|
| 4 |
<%= form_tag({:action => 'plugin'}) do %>
|
|
| 5 |
<div class="box tabular"> |
|
| 6 |
<%= render :partial => @partial, :locals => {:settings => @settings}%>
|
|
| 7 |
</div> |
|
| 8 |
<%= submit_tag l(:button_apply) %> |
|
| 9 |
<% end %> |
|
| 10 |
</div> |
|
| .svn/pristine/e1/e16f06cc6d0cf53d877dce169bf005137a43e454.svn-base | ||
|---|---|---|
| 1 |
<ul> |
|
| 2 |
<% if !@time_entry.nil? -%> |
|
| 3 |
<li><%= context_menu_link l(:button_edit), {:controller => 'timelog', :action => 'edit', :id => @time_entry},
|
|
| 4 |
:class => 'icon-edit', :disabled => !@can[:edit] %></li> |
|
| 5 |
<% else %> |
|
| 6 |
<li><%= context_menu_link l(:button_edit), {:controller => 'timelog', :action => 'bulk_edit', :ids => @time_entries.collect(&:id)},
|
|
| 7 |
:class => 'icon-edit', :disabled => !@can[:edit] %></li> |
|
| 8 |
<% end %> |
|
| 9 |
|
|
| 10 |
<%= call_hook(:view_time_entries_context_menu_start, {:time_entries => @time_entries, :can => @can, :back => @back }) %>
|
|
| 11 |
|
|
| 12 |
<% if @activities.present? -%> |
|
| 13 |
<li class="folder"> |
|
| 14 |
<a href="#" class="submenu"><%= l(:field_activity) %></a> |
|
| 15 |
<ul> |
|
| 16 |
<% @activities.each do |u| -%> |
|
| 17 |
<li><%= context_menu_link h(u.name), {:controller => 'timelog', :action => 'bulk_update', :ids => @time_entries.collect(&:id), :time_entry => {'activity_id' => u}, :back_url => @back}, :method => :post,
|
|
| 18 |
:selected => (@time_entry && u == @time_entry.activity), :disabled => !@can[:edit] %></li> |
|
| 19 |
<% end -%> |
|
| 20 |
<li><%= context_menu_link l(:label_none), {:controller => 'timelog', :action => 'bulk_update', :ids => @time_entries.collect(&:id), :time_entry => {'activity_id' => 'none'}, :back_url => @back}, :method => :post,
|
|
| 21 |
:selected => (@time_entry && @time_entry.activity.nil?), :disabled => !@can[:edit] %></li> |
|
| 22 |
</ul> |
|
| 23 |
</li> |
|
| 24 |
<% end %> |
|
| 25 |
|
|
| 26 |
<%= call_hook(:view_time_entries_context_menu_end, {:time_entries => @time_entries, :can => @can, :back => @back }) %>
|
|
| 27 |
|
|
| 28 |
<li> |
|
| 29 |
<%= context_menu_link l(:button_delete), |
|
| 30 |
{:controller => 'timelog', :action => 'destroy', :ids => @time_entries.collect(&:id), :back_url => @back},
|
|
| 31 |
:method => :delete, :data => {:confirm => l(:text_time_entries_destroy_confirmation)}, :class => 'icon-del', :disabled => !@can[:delete] %>
|
|
| 32 |
</li> |
|
| 33 |
</ul> |
|
| .svn/pristine/e1/e18b648e1cd178d3192044e7b2fe082fe4ae4170.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2012 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
require File.expand_path('../../../test_helper', __FILE__)
|
|
| 19 |
|
|
| 20 |
class RoutingSysTest < ActionController::IntegrationTest |
|
| 21 |
def test_sys |
|
| 22 |
assert_routing( |
|
| 23 |
{ :method => 'get', :path => "/sys/projects" },
|
|
| 24 |
{ :controller => 'sys', :action => 'projects' }
|
|
| 25 |
) |
|
| 26 |
assert_routing( |
|
| 27 |
{ :method => 'post', :path => "/sys/projects/testid/repository" },
|
|
| 28 |
{ :controller => 'sys', :action => 'create_project_repository', :id => 'testid' }
|
|
| 29 |
) |
|
| 30 |
assert_routing( |
|
| 31 |
{ :method => 'get', :path => "/sys/fetch_changesets" },
|
|
| 32 |
{ :controller => 'sys', :action => 'fetch_changesets' }
|
|
| 33 |
) |
|
| 34 |
end |
|
| 35 |
end |
|
| .svn/pristine/e1/e1bc9a07d6ad4cb9e3d25dfb56d8de5fa775e270.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2012 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
require File.expand_path('../../test_helper', __FILE__)
|
|
| 19 |
|
|
| 20 |
class SearchTest < ActiveSupport::TestCase |
|
| 21 |
fixtures :users, |
|
| 22 |
:members, |
|
| 23 |
:member_roles, |
|
| 24 |
:projects, |
|
| 25 |
:roles, |
|
| 26 |
:enabled_modules, |
|
| 27 |
:issues, |
|
| 28 |
:trackers, |
|
| 29 |
:journals, |
|
| 30 |
:journal_details, |
|
| 31 |
:repositories, |
|
| 32 |
:changesets |
|
| 33 |
|
|
| 34 |
def setup |
|
| 35 |
@project = Project.find(1) |
|
| 36 |
@issue_keyword = '%unable to print recipes%' |
|
| 37 |
@issue = Issue.find(1) |
|
| 38 |
@changeset_keyword = '%very first commit%' |
|
| 39 |
@changeset = Changeset.find(100) |
|
| 40 |
end |
|
| 41 |
|
|
| 42 |
def test_search_by_anonymous |
|
| 43 |
User.current = nil |
|
| 44 |
|
|
| 45 |
r = Issue.search(@issue_keyword).first |
|
| 46 |
assert r.include?(@issue) |
|
| 47 |
r = Changeset.search(@changeset_keyword).first |
|
| 48 |
assert r.include?(@changeset) |
|
| 49 |
|
|
| 50 |
# Removes the :view_changesets permission from Anonymous role |
|
| 51 |
remove_permission Role.anonymous, :view_changesets |
|
| 52 |
|
|
| 53 |
r = Issue.search(@issue_keyword).first |
|
| 54 |
assert r.include?(@issue) |
|
| 55 |
r = Changeset.search(@changeset_keyword).first |
|
| 56 |
assert !r.include?(@changeset) |
|
| 57 |
|
|
| 58 |
# Make the project private |
|
| 59 |
@project.update_attribute :is_public, false |
|
| 60 |
r = Issue.search(@issue_keyword).first |
|
| 61 |
assert !r.include?(@issue) |
|
| 62 |
r = Changeset.search(@changeset_keyword).first |
|
| 63 |
assert !r.include?(@changeset) |
|
| 64 |
end |
|
| 65 |
|
|
| 66 |
def test_search_by_user |
|
| 67 |
User.current = User.find_by_login('rhill')
|
|
| 68 |
assert User.current.memberships.empty? |
|
| 69 |
|
|
| 70 |
r = Issue.search(@issue_keyword).first |
|
| 71 |
assert r.include?(@issue) |
|
| 72 |
r = Changeset.search(@changeset_keyword).first |
|
| 73 |
assert r.include?(@changeset) |
|
| 74 |
|
|
| 75 |
# Removes the :view_changesets permission from Non member role |
|
| 76 |
remove_permission Role.non_member, :view_changesets |
|
| 77 |
|
|
| 78 |
r = Issue.search(@issue_keyword).first |
|
| 79 |
assert r.include?(@issue) |
|
| 80 |
r = Changeset.search(@changeset_keyword).first |
|
| 81 |
assert !r.include?(@changeset) |
|
| 82 |
|
|
| 83 |
# Make the project private |
|
| 84 |
@project.update_attribute :is_public, false |
|
| 85 |
r = Issue.search(@issue_keyword).first |
|
| 86 |
assert !r.include?(@issue) |
|
| 87 |
r = Changeset.search(@changeset_keyword).first |
|
| 88 |
assert !r.include?(@changeset) |
|
| 89 |
end |
|
| 90 |
|
|
| 91 |
def test_search_by_allowed_member |
|
| 92 |
User.current = User.find_by_login('jsmith')
|
|
| 93 |
assert User.current.projects.include?(@project) |
|
| 94 |
|
|
| 95 |
r = Issue.search(@issue_keyword).first |
|
| 96 |
assert r.include?(@issue) |
|
| 97 |
r = Changeset.search(@changeset_keyword).first |
|
| 98 |
assert r.include?(@changeset) |
|
| 99 |
|
|
| 100 |
# Make the project private |
|
| 101 |
@project.update_attribute :is_public, false |
|
| 102 |
r = Issue.search(@issue_keyword).first |
|
| 103 |
assert r.include?(@issue) |
|
| 104 |
r = Changeset.search(@changeset_keyword).first |
|
| 105 |
assert r.include?(@changeset) |
|
| 106 |
end |
|
| 107 |
|
|
| 108 |
def test_search_by_unallowed_member |
|
| 109 |
# Removes the :view_changesets permission from user's and non member role |
|
| 110 |
remove_permission Role.find(1), :view_changesets |
|
| 111 |
remove_permission Role.non_member, :view_changesets |
|
| 112 |
|
|
| 113 |
User.current = User.find_by_login('jsmith')
|
|
| 114 |
assert User.current.projects.include?(@project) |
|
| 115 |
|
|
| 116 |
r = Issue.search(@issue_keyword).first |
|
| 117 |
assert r.include?(@issue) |
|
| 118 |
r = Changeset.search(@changeset_keyword).first |
|
| 119 |
assert !r.include?(@changeset) |
|
| 120 |
|
|
| 121 |
# Make the project private |
|
| 122 |
@project.update_attribute :is_public, false |
|
| 123 |
r = Issue.search(@issue_keyword).first |
|
| 124 |
assert r.include?(@issue) |
|
| 125 |
r = Changeset.search(@changeset_keyword).first |
|
| 126 |
assert !r.include?(@changeset) |
|
| 127 |
end |
|
| 128 |
|
|
| 129 |
def test_search_issue_with_multiple_hits_in_journals |
|
| 130 |
i = Issue.find(1) |
|
| 131 |
assert_equal 2, i.journals.count(:all, :conditions => "notes LIKE '%notes%'") |
|
| 132 |
|
|
| 133 |
r = Issue.search('%notes%').first
|
|
| 134 |
assert_equal 1, r.size |
|
| 135 |
assert_equal i, r.first |
|
| 136 |
end |
|
| 137 |
|
|
| 138 |
private |
|
| 139 |
|
|
| 140 |
def remove_permission(role, permission) |
|
| 141 |
role.permissions = role.permissions - [ permission ] |
|
| 142 |
role.save |
|
| 143 |
end |
|
| 144 |
end |
|
| .svn/pristine/e1/e1ee7d45cedbd35f6e95dc6e86f4b927e7d66609.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2012 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
require 'builder' |
|
| 19 |
|
|
| 20 |
module Redmine |
|
| 21 |
module Views |
|
| 22 |
module Builders |
|
| 23 |
class Xml < ::Builder::XmlMarkup |
|
| 24 |
def initialize(request, response) |
|
| 25 |
super() |
|
| 26 |
instruct! |
|
| 27 |
end |
|
| 28 |
|
|
| 29 |
def output |
|
| 30 |
target! |
|
| 31 |
end |
|
| 32 |
|
|
| 33 |
def method_missing(sym, *args, &block) |
|
| 34 |
if args.size == 1 && args.first.is_a?(::Time) |
|
| 35 |
__send__ sym, args.first.xmlschema, &block |
|
| 36 |
else |
|
| 37 |
super |
|
| 38 |
end |
|
| 39 |
end |
|
| 40 |
|
|
| 41 |
def array(name, options={}, &block)
|
|
| 42 |
__send__ name, (options || {}).merge(:type => 'array'), &block
|
|
| 43 |
end |
|
| 44 |
end |
|
| 45 |
end |
|
| 46 |
end |
|
| 47 |
end |
|
Also available in: Unified diff