Revision 1298:4f746d8966dd .svn/pristine/30

View differences:

.svn/pristine/30/301185c13f555c3833de6896f8f45895314d605b.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2013  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 RoutingCommentsTest < ActionController::IntegrationTest
21
  def test_comments
22
    assert_routing(
23
        { :method => 'post', :path => "/news/567/comments" },
24
        { :controller => 'comments', :action => 'create', :id => '567' }
25
      )
26
    assert_routing(
27
        { :method => 'delete', :path => "/news/567/comments/15" },
28
        { :controller => 'comments', :action => 'destroy', :id => '567',
29
          :comment_id => '15' }
30
      )
31
  end
32
end
.svn/pristine/30/304b68e7e7a6cf907c51306f2e95b29f2a8946e9.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2011  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 RepositoryTest < ActiveSupport::TestCase
21
  fixtures :projects,
22
           :trackers,
23
           :projects_trackers,
24
           :enabled_modules,
25
           :repositories,
26
           :issues,
27
           :issue_statuses,
28
           :issue_categories,
29
           :changesets,
30
           :changes,
31
           :users,
32
           :members,
33
           :member_roles,
34
           :roles,
35
           :enumerations
36

  
37
  def setup
38
    @repository = Project.find(1).repository
39
  end
40

  
41
  def test_create
42
    repository = Repository::Subversion.new(:project => Project.find(3))
43
    assert !repository.save
44

  
45
    repository.url = "svn://localhost"
46
    assert repository.save
47
    repository.reload
48

  
49
    project = Project.find(3)
50
    assert_equal repository, project.repository
51
  end
52

  
53
  def test_destroy
54
    changesets = Changeset.count(:all, :conditions => "repository_id = 10")
55
    changes = Change.count(:all, :conditions => "repository_id = 10",
56
                           :include => :changeset)
57
    assert_difference 'Changeset.count', -changesets do
58
      assert_difference 'Change.count', -changes do
59
        Repository.find(10).destroy
60
      end
61
    end
62
  end
63

  
64
  def test_should_not_create_with_disabled_scm
65
    # disable Subversion
66
    with_settings :enabled_scm => ['Darcs', 'Git'] do
67
      repository = Repository::Subversion.new(
68
                      :project => Project.find(3), :url => "svn://localhost")
69
      assert !repository.save
70
      assert_equal I18n.translate('activerecord.errors.messages.invalid'),
71
                                  repository.errors.on(:type)
72
    end
73
  end
74

  
75
  def test_scan_changesets_for_issue_ids
76
    Setting.default_language = 'en'
77
    Setting.notified_events = ['issue_added','issue_updated']
78

  
79
    # choosing a status to apply to fix issues
80
    Setting.commit_fix_status_id = IssueStatus.find(
81
                                     :first,
82
                                     :conditions => ["is_closed = ?", true]).id
83
    Setting.commit_fix_done_ratio = "90"
84
    Setting.commit_ref_keywords = 'refs , references, IssueID'
85
    Setting.commit_fix_keywords = 'fixes , closes'
86
    Setting.default_language = 'en'
87
    ActionMailer::Base.deliveries.clear
88

  
89
    # make sure issue 1 is not already closed
90
    fixed_issue = Issue.find(1)
91
    assert !fixed_issue.status.is_closed?
92
    old_status = fixed_issue.status
93

  
94
    Repository.scan_changesets_for_issue_ids
95
    assert_equal [101, 102], Issue.find(3).changeset_ids
96

  
97
    # fixed issues
98
    fixed_issue.reload
99
    assert fixed_issue.status.is_closed?
100
    assert_equal 90, fixed_issue.done_ratio
101
    assert_equal [101], fixed_issue.changeset_ids
102

  
103
    # issue change
104
    journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
105
    assert_equal User.find_by_login('dlopper'), journal.user
106
    assert_equal 'Applied in changeset r2.', journal.notes
107

  
108
    # 2 email notifications
109
    assert_equal 2, ActionMailer::Base.deliveries.size
110
    mail = ActionMailer::Base.deliveries.first
111
    assert_kind_of TMail::Mail, mail
112
    assert mail.subject.starts_with?(
113
        "[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
114
    assert mail.body.include?(
115
        "Status changed from #{old_status} to #{fixed_issue.status}")
116

  
117
    # ignoring commits referencing an issue of another project
118
    assert_equal [], Issue.find(4).changesets
119
  end
120

  
121
  def test_for_changeset_comments_strip
122
    repository = Repository::Mercurial.create(
123
                    :project => Project.find( 4 ),
124
                    :url => '/foo/bar/baz' )
125
    comment = <<-COMMENT
126
    This is a loooooooooooooooooooooooooooong comment                                                   
127
                                                                                                       
128
                                                                                            
129
    COMMENT
130
    changeset = Changeset.new(
131
      :comments => comment, :commit_date => Time.now,
132
      :revision => 0, :scmid => 'f39b7922fb3c',
133
      :committer => 'foo <foo@example.com>',
134
      :committed_on => Time.now, :repository => repository )
135
    assert( changeset.save )
136
    assert_not_equal( comment, changeset.comments )
137
    assert_equal( 'This is a loooooooooooooooooooooooooooong comment',
138
                  changeset.comments )
139
  end
140

  
141
  def test_for_urls_strip_cvs
142
    repository = Repository::Cvs.create(
143
        :project => Project.find(4),
144
        :url => ' :pserver:login:password@host:/path/to/the/repository',
145
        :root_url => 'foo  ',
146
        :log_encoding => 'UTF-8')
147
    assert repository.save
148
    repository.reload
149
    assert_equal ':pserver:login:password@host:/path/to/the/repository',
150
                  repository.url
151
    assert_equal 'foo', repository.root_url
152
  end
153

  
154
  def test_for_urls_strip_subversion
155
    repository = Repository::Subversion.create(
156
        :project => Project.find(4),
157
        :url => ' file:///dummy   ')
158
    assert repository.save
159
    repository.reload
160
    assert_equal 'file:///dummy', repository.url
161
  end
162

  
163
  def test_for_urls_strip_git
164
    repository = Repository::Git.create(
165
        :project => Project.find(4),
166
        :url => ' c:\dummy   ')
167
    assert repository.save
168
    repository.reload
169
    assert_equal 'c:\dummy', repository.url
170
  end
171

  
172
  def test_manual_user_mapping
173
    assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
174
      c = Changeset.create!(
175
              :repository => @repository,
176
              :committer => 'foo',
177
              :committed_on => Time.now,
178
              :revision => 100,
179
              :comments => 'Committed by foo.'
180
            )
181
      assert_nil c.user
182
      @repository.committer_ids = {'foo' => '2'}
183
      assert_equal User.find(2), c.reload.user
184
      # committer is now mapped
185
      c = Changeset.create!(
186
              :repository => @repository,
187
              :committer => 'foo',
188
              :committed_on => Time.now,
189
              :revision => 101,
190
              :comments => 'Another commit by foo.'
191
            )
192
      assert_equal User.find(2), c.user
193
    end
194
  end
195

  
196
  def test_auto_user_mapping_by_username
197
    c = Changeset.create!(
198
          :repository   => @repository,
199
          :committer    => 'jsmith',
200
          :committed_on => Time.now,
201
          :revision     => 100,
202
          :comments     => 'Committed by john.'
203
        )
204
    assert_equal User.find(2), c.user
205
  end
206

  
207
  def test_auto_user_mapping_by_email
208
    c = Changeset.create!(
209
          :repository   => @repository,
210
          :committer    => 'john <jsmith@somenet.foo>',
211
          :committed_on => Time.now,
212
          :revision     => 100,
213
          :comments     => 'Committed by john.'
214
        )
215
    assert_equal User.find(2), c.user
216
  end
217

  
218
  def test_filesystem_avaialbe
219
    klass = Repository::Filesystem
220
    assert klass.scm_adapter_class
221
    assert_equal true, klass.scm_available
222
  end
223

  
224
  def test_merge_extra_info
225
    repo = Repository::Subversion.new(:project => Project.find(3))
226
    assert !repo.save
227
    repo.url = "svn://localhost"
228
    assert repo.save
229
    repo.reload
230
    project = Project.find(3)
231
    assert_equal repo, project.repository
232
    assert_nil repo.extra_info
233
    h1 = {"test_1" => {"test_11" => "test_value_11"}}
234
    repo.merge_extra_info(h1)
235
    assert_equal h1, repo.extra_info
236
    h2 = {"test_2" => {
237
                   "test_21" => "test_value_21",
238
                   "test_22" => "test_value_22",
239
                  }}
240
    repo.merge_extra_info(h2)
241
    assert_equal (h = {"test_11" => "test_value_11"}),
242
                 repo.extra_info["test_1"]
243
    assert_equal "test_value_21",
244
                 repo.extra_info["test_2"]["test_21"]
245
    h3 = {"test_2" => {
246
                   "test_23" => "test_value_23",
247
                   "test_24" => "test_value_24",
248
                  }}
249
    repo.merge_extra_info(h3)
250
    assert_equal (h = {"test_11" => "test_value_11"}),
251
                 repo.extra_info["test_1"]
252
    assert_nil repo.extra_info["test_2"]["test_21"]
253
    assert_equal "test_value_23",
254
                 repo.extra_info["test_2"]["test_23"]
255
  end
256
end
.svn/pristine/30/30787e3d5bfe04d8411e5332a384d8a1a749f767.svn-base
1
<h2><%= l(:label_board_plural) %></h2>
2

  
3
<table class="list boards">
4
  <thead><tr>
5
    <th><%= l(:label_board) %></th>
6
    <th><%= l(:label_topic_plural) %></th>
7
    <th><%= l(:label_message_plural) %></th>
8
    <th><%= l(:label_message_last) %></th>
9
  </tr></thead>
10
  <tbody>
11
<% Board.board_tree(@boards) do |board, level| %>
12
  <tr class="<%= cycle 'odd', 'even' %>">
13
    <td style="padding-left: <%= level * 18 %>px;">
14
      <%= link_to h(board.name), project_board_path(board.project, board), :class => "board" %><br />
15
      <%=h board.description %>
16
    </td>
17
    <td class="topic-count"><%= board.topics_count %></td>
18
    <td class="message-count"><%= board.messages_count %></td>
19
    <td class="last-message">
20
      <% if board.last_message %>
21
      <%= authoring board.last_message.created_on, board.last_message.author %><br />
22
      <%= link_to_message board.last_message %>
23
      <% end %>
24
    </td>
25
  </tr>
26
<% end %>
27
  </tbody>
28
</table>
29

  
30
<% other_formats_links do |f| %>
31
  <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_messages => 1, :key => User.current.rss_key} %>
32
<% end %>
33

  
34
<% content_for :header_tags do %>
35
  <%= auto_discovery_link_tag(:atom, {:controller => 'activities', :action => 'index', :id => @project, :format => 'atom', :show_messages => 1, :key => User.current.rss_key}) %>
36
<% end %>
37

  
38
<% html_title l(:label_board_plural) %>
.svn/pristine/30/30881f171a667b3a44449e71bb74b80be13859b2.svn-base
1
module CodeRay
2
module Scanners
3
  
4
  # Scanner for JSON (JavaScript Object Notation).
5
  class JSON < Scanner
6
    
7
    register_for :json
8
    file_extension 'json'
9
    
10
    KINDS_NOT_LOC = [
11
      :float, :char, :content, :delimiter,
12
      :error, :integer, :operator, :value,
13
    ]  # :nodoc:
14
    
15
    ESCAPE = / [bfnrt\\"\/] /x  # :nodoc:
16
    UNICODE_ESCAPE = / u[a-fA-F0-9]{4} /x  # :nodoc:
17
    
18
  protected
19
    
20
    # See http://json.org/ for a definition of the JSON lexic/grammar.
21
    def scan_tokens encoder, options
22
      
23
      state = :initial
24
      stack = []
25
      key_expected = false
26
      
27
      until eos?
28
        
29
        case state
30
        
31
        when :initial
32
          if match = scan(/ \s+ /x)
33
            encoder.text_token match, :space
34
          elsif match = scan(/"/)
35
            state = key_expected ? :key : :string
36
            encoder.begin_group state
37
            encoder.text_token match, :delimiter
38
          elsif match = scan(/ [:,\[{\]}] /x)
39
            encoder.text_token match, :operator
40
            case match
41
            when ':' then key_expected = false
42
            when ',' then key_expected = true if stack.last == :object
43
            when '{' then stack << :object; key_expected = true
44
            when '[' then stack << :array
45
            when '}', ']' then stack.pop  # no error recovery, but works for valid JSON
46
            end
47
          elsif match = scan(/ true | false | null /x)
48
            encoder.text_token match, :value
49
          elsif match = scan(/ -? (?: 0 | [1-9]\d* ) /x)
50
            if scan(/ \.\d+ (?:[eE][-+]?\d+)? | [eE][-+]? \d+ /x)
51
              match << matched
52
              encoder.text_token match, :float
53
            else
54
              encoder.text_token match, :integer
55
            end
56
          else
57
            encoder.text_token getch, :error
58
          end
59
          
60
        when :string, :key
61
          if match = scan(/[^\\"]+/)
62
            encoder.text_token match, :content
63
          elsif match = scan(/"/)
64
            encoder.text_token match, :delimiter
65
            encoder.end_group state
66
            state = :initial
67
          elsif match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
68
            encoder.text_token match, :char
69
          elsif match = scan(/\\./m)
70
            encoder.text_token match, :content
71
          elsif match = scan(/ \\ | $ /x)
72
            encoder.end_group state
73
            encoder.text_token match, :error
74
            state = :initial
75
          else
76
            raise_inspect "else case \" reached; %p not handled." % peek(1), encoder
77
          end
78
          
79
        else
80
          raise_inspect 'Unknown state: %p' % [state], encoder
81
          
82
        end
83
      end
84
      
85
      if [:string, :key].include? state
86
        encoder.end_group state
87
      end
88
      
89
      encoder
90
    end
91
    
92
  end
93
  
94
end
95
end
.svn/pristine/30/308a50990fe7138ee80b066400a54a3b1b066faf.svn-base
1
<%= TestHelper.view_path_for __FILE__ %>
.svn/pristine/30/308f688f7ea9b63ad1f36c2cfc3b151507bfbaea.svn-base
1
api.array :time_entries, api_meta(:total_count => @entry_count, :offset => @offset, :limit => @limit) do
2
  @entries.each do |time_entry|
3
    api.time_entry do
4
      api.id time_entry.id
5
      api.project(:id => time_entry.project_id, :name => time_entry.project.name) unless time_entry.project.nil?
6
      api.issue(:id => time_entry.issue_id) unless time_entry.issue.nil?
7
      api.user(:id => time_entry.user_id, :name => time_entry.user.name) unless time_entry.user.nil?
8
      api.activity(:id => time_entry.activity_id, :name => time_entry.activity.name) unless time_entry.activity.nil?
9
      api.hours time_entry.hours
10
      api.comments time_entry.comments
11
      api.spent_on time_entry.spent_on
12
      api.created_on time_entry.created_on
13
      api.updated_on time_entry.updated_on
14
    end
15
  end
16
end

Also available in: Unified diff