Revision 1297:0a574315af3e .svn/pristine/89

View differences:

.svn/pristine/89/893b6a5f960b2cbb71a8a74d8e070397749de965.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 DocumentsControllerTest < ActionController::TestCase
21
  fixtures :projects, :users, :roles, :members, :member_roles,
22
           :enabled_modules, :documents, :enumerations,
23
           :groups_users, :attachments
24

  
25
  def setup
26
    User.current = nil
27
  end
28

  
29
  def test_index
30
    # Sets a default category
31
    e = Enumeration.find_by_name('Technical documentation')
32
    e.update_attributes(:is_default => true)
33

  
34
    get :index, :project_id => 'ecookbook'
35
    assert_response :success
36
    assert_template 'index'
37
    assert_not_nil assigns(:grouped)
38

  
39
    # Default category selected in the new document form
40
    assert_tag :select, :attributes => {:name => 'document[category_id]'},
41
                        :child => {:tag => 'option', :attributes => {:selected => 'selected'},
42
                                                     :content => 'Technical documentation'}
43

  
44
    assert ! DocumentCategory.find(16).active?
45
    assert_no_tag :option, :attributes => {:value => '16'},
46
                           :parent => {:tag => 'select', :attributes => {:id => 'document_category_id'} }
47
  end
48

  
49
  def test_index_grouped_by_date
50
    get :index, :project_id => 'ecookbook', :sort_by => 'date'
51
    assert_response :success
52
    assert_tag 'h3', :content => '2007-02-12'
53
  end
54

  
55
  def test_index_grouped_by_title
56
    get :index, :project_id => 'ecookbook', :sort_by => 'title'
57
    assert_response :success
58
    assert_tag 'h3', :content => 'T'
59
  end
60

  
61
  def test_index_grouped_by_author
62
    get :index, :project_id => 'ecookbook', :sort_by => 'author'
63
    assert_response :success
64
    assert_tag 'h3', :content => 'John Smith'
65
  end
66

  
67
  def test_index_with_long_description
68
    # adds a long description to the first document
69
    doc = documents(:documents_001)
70
    doc.update_attributes(:description => <<LOREM)
71
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut egestas, mi vehicula varius varius, ipsum massa fermentum orci, eget tristique ante sem vel mi. Nulla facilisi. Donec enim libero, luctus ac sagittis sit amet, vehicula sagittis magna. Duis ultrices molestie ante, eget scelerisque sem iaculis vitae. Etiam fermentum mauris vitae metus pharetra condimentum fermentum est pretium. Proin sollicitudin elementum quam quis pharetra.  Aenean facilisis nunc quis elit volutpat mollis. Aenean eleifend varius euismod. Ut dolor est, congue eget dapibus eget, elementum eu odio. Integer et lectus neque, nec scelerisque nisi. EndOfLineHere
72

  
73
Vestibulum non velit mi. Aliquam scelerisque libero ut nulla fringilla a sollicitudin magna rhoncus.  Praesent a nunc lorem, ac porttitor eros. Sed ac diam nec neque interdum adipiscing quis quis justo. Donec arcu nunc, fringilla eu dictum at, venenatis ac sem. Vestibulum quis elit urna, ac mattis sapien. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
74
LOREM
75

  
76
    get :index, :project_id => 'ecookbook'
77
    assert_response :success
78
    assert_template 'index'
79

  
80
    # should only truncate on new lines to avoid breaking wiki formatting
81
    assert_select '.wiki p', :text => (doc.description.split("\n").first + '...')
82
    assert_select '.wiki p', :text => Regexp.new(Regexp.escape("EndOfLineHere..."))
83
  end
84

  
85
  def test_show
86
    get :show, :id => 1
87
    assert_response :success
88
    assert_template 'show'
89
  end
90

  
91
  def test_new
92
    @request.session[:user_id] = 2
93
    get :new, :project_id => 1
94
    assert_response :success
95
    assert_template 'new'
96
  end
97

  
98
  def test_create_with_one_attachment
99
    ActionMailer::Base.deliveries.clear
100
    @request.session[:user_id] = 2
101
    set_tmp_attachments_directory
102

  
103
    with_settings :notified_events => %w(document_added) do
104
      post :create, :project_id => 'ecookbook',
105
               :document => { :title => 'DocumentsControllerTest#test_post_new',
106
                              :description => 'This is a new document',
107
                              :category_id => 2},
108
               :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
109
    end
110
    assert_redirected_to '/projects/ecookbook/documents'
111

  
112
    document = Document.find_by_title('DocumentsControllerTest#test_post_new')
113
    assert_not_nil document
114
    assert_equal Enumeration.find(2), document.category
115
    assert_equal 1, document.attachments.size
116
    assert_equal 'testfile.txt', document.attachments.first.filename
117
    assert_equal 1, ActionMailer::Base.deliveries.size
118
  end
119

  
120
  def test_create_with_failure
121
    @request.session[:user_id] = 2
122
    assert_no_difference 'Document.count' do
123
      post :create, :project_id => 'ecookbook', :document => { :title => ''}
124
    end
125
    assert_response :success
126
    assert_template 'new'
127
  end
128

  
129
  def test_create_non_default_category
130
    @request.session[:user_id] = 2
131
    category2 = Enumeration.find_by_name('User documentation')
132
    category2.update_attributes(:is_default => true)
133
    category1 = Enumeration.find_by_name('Uncategorized')
134
    post :create,
135
         :project_id => 'ecookbook',
136
         :document => { :title => 'no default',
137
                        :description => 'This is a new document',
138
                        :category_id => category1.id }
139
    assert_redirected_to '/projects/ecookbook/documents'
140
    doc = Document.find_by_title('no default')
141
    assert_not_nil doc
142
    assert_equal category1.id, doc.category_id
143
    assert_equal category1, doc.category
144
  end
145

  
146
  def test_edit
147
    @request.session[:user_id] = 2
148
    get :edit, :id => 1
149
    assert_response :success
150
    assert_template 'edit'
151
  end
152

  
153
  def test_update
154
    @request.session[:user_id] = 2
155
    put :update, :id => 1, :document => {:title => 'test_update'}
156
    assert_redirected_to '/documents/1'
157
    document = Document.find(1)
158
    assert_equal 'test_update', document.title
159
  end
160

  
161
  def test_update_with_failure
162
    @request.session[:user_id] = 2
163
    put :update, :id => 1, :document => {:title => ''}
164
    assert_response :success
165
    assert_template 'edit'
166
  end
167

  
168
  def test_destroy
169
    @request.session[:user_id] = 2
170
    assert_difference 'Document.count', -1 do
171
      delete :destroy, :id => 1
172
    end
173
    assert_redirected_to '/projects/ecookbook/documents'
174
    assert_nil Document.find_by_id(1)
175
  end
176

  
177
  def test_add_attachment
178
    @request.session[:user_id] = 2
179
    assert_difference 'Attachment.count' do
180
      post :add_attachment, :id => 1,
181
        :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
182
    end
183
    attachment = Attachment.first(:order => 'id DESC')
184
    assert_equal Document.find(1), attachment.container
185
  end
186
end
.svn/pristine/89/894d13790f5ed434472bb7c3f91f2b053917338e.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
class IssuePriority < Enumeration
19
  has_many :issues, :foreign_key => 'priority_id'
20

  
21
  after_destroy {|priority| priority.class.compute_position_names}
22
  after_save {|priority| priority.class.compute_position_names if priority.position_changed? && priority.position}
23

  
24
  OptionName = :enumeration_issue_priorities
25

  
26
  def option_name
27
    OptionName
28
  end
29

  
30
  def objects_count
31
    issues.count
32
  end
33

  
34
  def transfer_relations(to)
35
    issues.update_all("priority_id = #{to.id}")
36
  end
37

  
38
  def css_classes
39
    "priority-#{id} priority-#{position_name}"
40
  end
41

  
42
  # Clears position_name for all priorities
43
  # Called from migration 20121026003537_populate_enumerations_position_name
44
  def self.clear_position_names
45
    update_all :position_name => nil
46
  end
47

  
48
  # Updates position_name for active priorities
49
  # Called from migration 20121026003537_populate_enumerations_position_name
50
  def self.compute_position_names
51
    priorities = where(:active => true).all.sort_by(&:position)
52
    if priorities.any?
53
      default = priorities.detect(&:is_default?) || priorities[(priorities.size - 1) / 2]
54
      priorities.each_with_index do |priority, index|
55
        name = case
56
          when priority.position == default.position
57
            "default"
58
          when priority.position < default.position
59
            index == 0 ? "lowest" : "low#{index+1}"
60
          else
61
            index == (priorities.size - 1) ? "highest" : "high#{priorities.size - index}"
62
          end
63

  
64
        update_all({:position_name => name}, :id => priority.id)
65
      end
66
    end
67
  end
68
end
.svn/pristine/89/8978a97f0061cf740fd3439d74e96fa4ac59cad8.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
module RedmineMenuTestHelper
21
  # Assertions
22
  def assert_number_of_items_in_menu(menu_name, count)
23
    assert Redmine::MenuManager.items(menu_name).size >= count, "Menu has less than #{count} items"
24
  end
25

  
26
  def assert_menu_contains_item_named(menu_name, item_name)
27
    assert Redmine::MenuManager.items(menu_name).collect(&:name).include?(item_name.to_sym), "Menu did not have an item named #{item_name}"
28
  end
29

  
30
  # Helpers
31
  def get_menu_item(menu_name, item_name)
32
    Redmine::MenuManager.items(menu_name).find {|item| item.name == item_name.to_sym}
33
  end
34
end
35

  
36
class RedmineTest < ActiveSupport::TestCase
37
  include RedmineMenuTestHelper
38

  
39
  def test_top_menu
40
    assert_number_of_items_in_menu :top_menu, 5
41
    assert_menu_contains_item_named :top_menu, :home
42
    assert_menu_contains_item_named :top_menu, :my_page
43
    assert_menu_contains_item_named :top_menu, :projects
44
    assert_menu_contains_item_named :top_menu, :administration
45
    assert_menu_contains_item_named :top_menu, :help
46
  end
47

  
48
  def test_account_menu
49
    assert_number_of_items_in_menu :account_menu, 4
50
    assert_menu_contains_item_named :account_menu, :login
51
    assert_menu_contains_item_named :account_menu, :register
52
    assert_menu_contains_item_named :account_menu, :my_account
53
    assert_menu_contains_item_named :account_menu, :logout
54
  end
55

  
56
  def test_application_menu
57
    assert_number_of_items_in_menu :application_menu, 0
58
  end
59

  
60
  def test_admin_menu
61
    assert_number_of_items_in_menu :admin_menu, 0
62
  end
63

  
64
  def test_project_menu
65
    assert_number_of_items_in_menu :project_menu, 14
66
    assert_menu_contains_item_named :project_menu, :overview
67
    assert_menu_contains_item_named :project_menu, :activity
68
    assert_menu_contains_item_named :project_menu, :roadmap
69
    assert_menu_contains_item_named :project_menu, :issues
70
    assert_menu_contains_item_named :project_menu, :new_issue
71
    assert_menu_contains_item_named :project_menu, :calendar
72
    assert_menu_contains_item_named :project_menu, :gantt
73
    assert_menu_contains_item_named :project_menu, :news
74
    assert_menu_contains_item_named :project_menu, :documents
75
    assert_menu_contains_item_named :project_menu, :wiki
76
    assert_menu_contains_item_named :project_menu, :boards
77
    assert_menu_contains_item_named :project_menu, :files
78
    assert_menu_contains_item_named :project_menu, :repository
79
    assert_menu_contains_item_named :project_menu, :settings
80
  end
81

  
82
  def test_new_issue_should_have_root_as_a_parent
83
    new_issue = get_menu_item(:project_menu, :new_issue)
84
    assert_equal :root, new_issue.parent.name
85
  end
86
end
.svn/pristine/89/8986d7af9b4225df9b8eb9cb006c26d74c370e89.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 RepositoriesBazaarControllerTest < ActionController::TestCase
21
  tests RepositoriesController
22

  
23
  fixtures :projects, :users, :roles, :members, :member_roles,
24
           :repositories, :enabled_modules
25

  
26
  REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository/trunk').to_s
27
  PRJ_ID = 3
28

  
29
  def setup
30
    User.current = nil
31
    @project = Project.find(PRJ_ID)
32
    @repository = Repository::Bazaar.create(
33
                    :project      => @project,
34
                    :url          => REPOSITORY_PATH,
35
                    :log_encoding => 'UTF-8')
36
    assert @repository
37
  end
38

  
39
  if File.directory?(REPOSITORY_PATH)
40
    def test_get_new
41
      @request.session[:user_id] = 1
42
      @project.repository.destroy
43
      get :new, :project_id => 'subproject1', :repository_scm => 'Bazaar'
44
      assert_response :success
45
      assert_template 'new'
46
      assert_kind_of Repository::Bazaar, assigns(:repository)
47
      assert assigns(:repository).new_record?
48
    end
49

  
50
    def test_browse_root
51
      get :show, :id => PRJ_ID
52
      assert_response :success
53
      assert_template 'show'
54
      assert_not_nil assigns(:entries)
55
      assert_equal 2, assigns(:entries).size
56
      assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'}
57
      assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'}
58
    end
59

  
60
    def test_browse_directory
61
      get :show, :id => PRJ_ID, :path => repository_path_hash(['directory'])[:param]
62
      assert_response :success
63
      assert_template 'show'
64
      assert_not_nil assigns(:entries)
65
      assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name)
66
      entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
67
      assert_not_nil entry
68
      assert_equal 'file', entry.kind
69
      assert_equal 'directory/edit.png', entry.path
70
    end
71

  
72
    def test_browse_at_given_revision
73
      get :show, :id => PRJ_ID, :path => repository_path_hash([])[:param],
74
          :rev => 3
75
      assert_response :success
76
      assert_template 'show'
77
      assert_not_nil assigns(:entries)
78
      assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'],
79
                   assigns(:entries).collect(&:name)
80
    end
81

  
82
    def test_changes
83
      get :changes, :id => PRJ_ID,
84
          :path => repository_path_hash(['doc-mkdir.txt'])[:param]
85
      assert_response :success
86
      assert_template 'changes'
87
      assert_tag :tag => 'h2', :content => 'doc-mkdir.txt'
88
    end
89

  
90
    def test_entry_show
91
      get :entry, :id => PRJ_ID,
92
          :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param]
93
      assert_response :success
94
      assert_template 'entry'
95
      # Line 19
96
      assert_tag :tag => 'th',
97
                 :content => /29/,
98
                 :attributes => { :class => /line-num/ },
99
                 :sibling => { :tag => 'td', :content => /Show help message/ }
100
    end
101

  
102
    def test_entry_download
103
      get :entry, :id => PRJ_ID,
104
          :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param],
105
          :format => 'raw'
106
      assert_response :success
107
      # File content
108
      assert @response.body.include?('Show help message')
109
    end
110

  
111
    def test_directory_entry
112
      get :entry, :id => PRJ_ID,
113
          :path => repository_path_hash(['directory'])[:param]
114
      assert_response :success
115
      assert_template 'show'
116
      assert_not_nil assigns(:entry)
117
      assert_equal 'directory', assigns(:entry).name
118
    end
119

  
120
    def test_diff
121
      # Full diff of changeset 3
122
      ['inline', 'sbs'].each do |dt|
123
        get :diff, :id => PRJ_ID, :rev => 3, :type => dt
124
        assert_response :success
125
        assert_template 'diff'
126
        # Line 11 removed
127
        assert_tag :tag => 'th',
128
                   :content => '11',
129
                   :sibling => { :tag => 'td',
130
                                 :attributes => { :class => /diff_out/ },
131
                                 :content => /Display more information/ }
132
      end
133
    end
134

  
135
    def test_annotate
136
      get :annotate, :id => PRJ_ID,
137
          :path => repository_path_hash(['doc-mkdir.txt'])[:param]
138
      assert_response :success
139
      assert_template 'annotate'
140
      assert_tag :tag => 'th', :content => '2',
141
                 :sibling => {
142
                    :tag => 'td',
143
                    :child => {
144
                       :tag => 'a',
145
                       :content => '3'
146
                       }
147
                    }
148
      assert_tag :tag => 'th', :content => '2',
149
                 :sibling => { :tag => 'td', :content => /jsmith/ }
150
      assert_tag :tag => 'th', :content => '2',
151
                 :sibling => {
152
                    :tag => 'td',
153
                    :child => {
154
                       :tag => 'a',
155
                       :content => '3'
156
                       }
157
                    }
158
      assert_tag :tag => 'th', :content => '2',
159
                 :sibling => { :tag => 'td', :content => /Main purpose/ }
160
    end
161

  
162
    def test_destroy_valid_repository
163
      @request.session[:user_id] = 1 # admin
164
      assert_equal 0, @repository.changesets.count
165
      @repository.fetch_changesets
166
      assert @repository.changesets.count > 0
167

  
168
      assert_difference 'Repository.count', -1 do
169
        delete :destroy, :id => @repository.id
170
      end
171
      assert_response 302
172
      @project.reload
173
      assert_nil @project.repository
174
    end
175

  
176
    def test_destroy_invalid_repository
177
      @request.session[:user_id] = 1 # admin
178
      @project.repository.destroy
179
      @repository = Repository::Bazaar.create!(
180
                    :project      => @project,
181
                    :url          => "/invalid",
182
                    :log_encoding => 'UTF-8')
183
      @repository.fetch_changesets
184
      @repository.reload
185
      assert_equal 0, @repository.changesets.count
186

  
187
      assert_difference 'Repository.count', -1 do
188
        delete :destroy, :id => @repository.id
189
      end
190
      assert_response 302
191
      @project.reload
192
      assert_nil @project.repository
193
    end
194
  else
195
    puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
196
    def test_fake; assert true end
197
  end
198
end
.svn/pristine/89/89ce597feae0a741c7652fb0adcafccae6118a18.svn-base
1
<div class="attachments">
2
<% for attachment in attachments %>
3
<p><%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%>
4
  <% if attachment.is_text? %>
5
    <%= link_to image_tag('magnifier.png'),
6
                :controller => 'attachments', :action => 'show',
7
                :id => attachment, :filename => attachment.filename %>
8
  <% end %>
9
  <%= h(" - #{attachment.description}") unless attachment.description.blank? %>
10
  <span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
11
  <% if options[:deletable] %>
12
    <%= link_to image_tag('delete.png'), attachment_path(attachment),
13
                                         :data => {:confirm => l(:text_are_you_sure)},
14
                                         :method => :delete,
15
                                         :class => 'delete',
16
                                         :title => l(:button_delete) %>
17
  <% end %>
18
  <% if options[:author] %>
19
    <span class="author"><%= h(attachment.author) %>, <%= format_time(attachment.created_on) %></span>
20
  <% end %>
21
  </p>
22
<% end %>
23
<% if defined?(thumbnails) && thumbnails %>
24
  <% images = attachments.select(&:thumbnailable?) %>
25
  <% if images.any? %>
26
  <div class="thumbnails">
27
    <% images.each do |attachment| %>
28
      <div><%= thumbnail_tag(attachment) %></div>
29
    <% end %>
30
  </div>
31
  <% end %>
32
<% end %>
33
</div>
.svn/pristine/89/89e50c2e8b8d5c2174225ba4707520b699d0f276.svn-base
1
# Mocks out OpenID
2
#
3
# http://www.northpub.com/articles/2007/04/02/testing-openid-support
4
module OpenIdAuthentication
5

  
6
  EXTENSION_FIELDS = {'email'    => 'user@somedomain.com',
7
                      'nickname' => 'cool_user',
8
                      'country'  => 'US',
9
                      'postcode' => '12345',
10
                      'fullname' => 'Cool User',
11
                      'dob'      => '1970-04-01',
12
                      'language' => 'en',
13
                      'timezone' => 'America/New_York'}
14

  
15
  protected
16

  
17
    def authenticate_with_open_id(identity_url = params[:openid_url], options = {}) #:doc:
18
      if User.find_by_identity_url(identity_url) || identity_url.include?('good')
19
        extension_response_fields = {}
20

  
21
        # Don't process registration fields unless it is requested.
22
        unless identity_url.include?('blank') || (options[:required].nil? && options[:optional].nil?)
23

  
24
          options[:required].each do |field|
25
            extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s]
26
          end unless options[:required].nil?
27

  
28
          options[:optional].each do |field|
29
            extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s]
30
          end unless options[:optional].nil?
31
        end
32

  
33
        yield Result[:successful], identity_url , extension_response_fields
34
      else
35
        logger.info "OpenID authentication failed: #{identity_url}"
36
        yield Result[:failed], identity_url, nil
37
      end
38
    end
39

  
40
  private
41

  
42
    def add_simple_registration_fields(open_id_response, fields)
43
      open_id_response.add_extension_arg('sreg', 'required', [ fields[:required] ].flatten * ',') if fields[:required]
44
      open_id_response.add_extension_arg('sreg', 'optional', [ fields[:optional] ].flatten * ',') if fields[:optional]
45
    end
46
end

Also available in: Unified diff