Commit f448634b0cff1c24fe97c43c1bd2634c0bf555c5
1 parent
80b43289
Exists in
master
and in
29 other branches
rails3: fix custom_forms plugin
Showing
26 changed files
with
93 additions
and
79 deletions
Show diff stats
plugins/custom_forms/controllers/custom_forms_plugin_myprofile_controller.rb
... | ... | @@ -75,13 +75,14 @@ class CustomFormsPluginMyprofileController < MyProfileController |
75 | 75 | format.csv do |
76 | 76 | # CSV contains form fields, timestamp, user name and user email |
77 | 77 | columns = @form.fields.count + 3 |
78 | - csv_content = CSV.generate_line(['Timestamp', 'Name', 'Email'] + @form.fields.map(&:name)) + "\n" | |
78 | + csv_content = CSV.generate_line(['Timestamp', 'Name', 'Email'] + @form.fields.map(&:name)) | |
79 | 79 | @submissions.each do |s| |
80 | 80 | fields = [s.updated_at.strftime('%Y/%m/%d %T %Z'), s.profile.present? ? s.profile.name : s.author_name, s.profile.present? ? s.profile.email : s.author_email] |
81 | 81 | @form.fields.each do |f| |
82 | 82 | fields << s.answers.select{|a| a.field == f}.map{|answer| answer.to_s} |
83 | 83 | end |
84 | - CSV.generate_row(fields, columns, csv_content) | |
84 | + fields = fields.flatten | |
85 | + csv_content << CSV.generate_line(fields + (columns - fields.size).times.map{""}) | |
85 | 86 | end |
86 | 87 | send_data csv_content, :type => 'text/csv', :filename => "#{@form.name}.csv" |
87 | 88 | end | ... | ... |
plugins/custom_forms/controllers/custom_forms_plugin_profile_controller.rb
... | ... | @@ -7,9 +7,9 @@ class CustomFormsPluginProfileController < ProfileController |
7 | 7 | @form = CustomFormsPlugin::Form.find(params[:id]) |
8 | 8 | if user |
9 | 9 | @submission ||= CustomFormsPlugin::Submission.find_by_form_id_and_profile_id(@form.id,user.id) |
10 | - @submission ||= CustomFormsPlugin::Submission.new(:form_id => @form.id, :profile_id => user.id) | |
10 | + @submission ||= CustomFormsPlugin::Submission.new(:form => @form, :profile => user) | |
11 | 11 | else |
12 | - @submission ||= CustomFormsPlugin::Submission.new(:form_id => @form.id) | |
12 | + @submission ||= CustomFormsPlugin::Submission.new(:form => @form) | |
13 | 13 | end |
14 | 14 | |
15 | 15 | # build the answers | ... | ... |
plugins/custom_forms/lib/custom_forms_plugin/alternative.rb
plugins/custom_forms/lib/custom_forms_plugin/answer.rb
1 | -class CustomFormsPlugin::Answer < Noosfero::Plugin::ActiveRecord | |
1 | +class CustomFormsPlugin::Answer < ActiveRecord::Base | |
2 | + set_table_name :custom_forms_plugin_answers | |
2 | 3 | belongs_to :field, :class_name => 'CustomFormsPlugin::Field' |
3 | 4 | belongs_to :submission, :class_name => 'CustomFormsPlugin::Submission' |
4 | 5 | |
5 | 6 | validates_presence_of :field |
6 | 7 | validate :value_mandatory, :if => 'field.present?' |
7 | 8 | |
9 | + attr_accessible :field, :value, :submission | |
10 | + | |
8 | 11 | def value_mandatory |
9 | 12 | if field.mandatory && value.blank? |
10 | 13 | errors.add(:value, _("is mandatory.").fix_i18n) | ... | ... |
plugins/custom_forms/lib/custom_forms_plugin/field.rb
... | ... | @@ -3,6 +3,8 @@ class CustomFormsPlugin::Field < ActiveRecord::Base |
3 | 3 | |
4 | 4 | validates_presence_of :name |
5 | 5 | |
6 | + attr_accessible :name, :form, :mandatory, :type, :position, :default_value, :select_field_type, :alternatives_attributes | |
7 | + | |
6 | 8 | belongs_to :form, :class_name => 'CustomFormsPlugin::Form' |
7 | 9 | has_many :answers, :class_name => 'CustomFormsPlugin::Answer' |
8 | 10 | ... | ... |
plugins/custom_forms/lib/custom_forms_plugin/form.rb
... | ... | @@ -13,6 +13,8 @@ class CustomFormsPlugin::Form < Noosfero::Plugin::ActiveRecord |
13 | 13 | validate :period_range, :if => Proc.new { |f| f.begining.present? && f.ending.present? } |
14 | 14 | validate :access_format |
15 | 15 | |
16 | + attr_accessible :name, :profile, :for_admission, :access, :begining, :ending, :description, :fields_attributes, :profile_id, :on_membership | |
17 | + | |
16 | 18 | before_validation do |form| |
17 | 19 | form.slug = form.name.to_slug if form.name.present? |
18 | 20 | form.access = nil if form.access.blank? |
... | ... | @@ -23,11 +25,11 @@ class CustomFormsPlugin::Form < Noosfero::Plugin::ActiveRecord |
23 | 25 | tasks.each {|task| task.cancel} |
24 | 26 | end |
25 | 27 | |
26 | - named_scope :from, lambda {|profile| {:conditions => {:profile_id => profile.id}}} | |
27 | - named_scope :on_memberships, {:conditions => {:on_membership => true, :for_admission => false}} | |
28 | - named_scope :for_admissions, {:conditions => {:for_admission => true}} | |
28 | + scope :from, lambda {|profile| {:conditions => {:profile_id => profile.id}}} | |
29 | + scope :on_memberships, {:conditions => {:on_membership => true, :for_admission => false}} | |
30 | + scope :for_admissions, {:conditions => {:for_admission => true}} | |
29 | 31 | =begin |
30 | - named_scope :accessible_to lambda do |profile| | |
32 | + scope :accessible_to lambda do |profile| | |
31 | 33 | #TODO should verify is profile is associated with the form owner |
32 | 34 | profile_associated = ??? |
33 | 35 | {:conditions => [" | ... | ... |
plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb
... | ... | @@ -5,7 +5,7 @@ class CustomFormsPlugin::MembershipSurvey < Task |
5 | 5 | |
6 | 6 | include CustomFormsPlugin::Helper |
7 | 7 | |
8 | - named_scope :from, lambda {|profile| {:conditions => {:requestor_id => profile.id}}} | |
8 | + scope :from, lambda {|profile| {:conditions => {:requestor_id => profile.id}}} | |
9 | 9 | |
10 | 10 | def perform |
11 | 11 | form = CustomFormsPlugin::Form.find(form_id) | ... | ... |
plugins/custom_forms/lib/custom_forms_plugin/submission.rb
... | ... | @@ -4,6 +4,8 @@ class CustomFormsPlugin::Submission < Noosfero::Plugin::ActiveRecord |
4 | 4 | |
5 | 5 | has_many :answers, :class_name => 'CustomFormsPlugin::Answer', :dependent => :destroy |
6 | 6 | |
7 | + attr_accessible :form, :profile | |
8 | + | |
7 | 9 | validates_presence_of :form |
8 | 10 | validates_presence_of :author_name, :author_email, :if => lambda {|submission| submission.profile.nil?} |
9 | 11 | validates_uniqueness_of :author_email, :scope => :form_id, :allow_nil => true | ... | ... |
plugins/custom_forms/lib/custom_forms_plugin/text_field.rb
plugins/custom_forms/lib/ext/role_assignment_trigger.rb
plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb
... | ... | @@ -41,7 +41,7 @@ class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase |
41 | 41 | format = '%Y-%m-%d %H:%M' |
42 | 42 | begining = Time.now.strftime(format) |
43 | 43 | ending = (Time.now + 1.day).strftime(format) |
44 | - assert_difference CustomFormsPlugin::Form, :count, 1 do | |
44 | + assert_difference 'CustomFormsPlugin::Form.count', 1 do | |
45 | 45 | post :create, :profile => profile.identifier, |
46 | 46 | :form => { |
47 | 47 | :name => 'My Form', |
... | ... | @@ -102,7 +102,7 @@ class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase |
102 | 102 | :type => 'CustomFormsPlugin::TextField' |
103 | 103 | } |
104 | 104 | end |
105 | - assert_difference CustomFormsPlugin::Form, :count, 1 do | |
105 | + assert_difference 'CustomFormsPlugin::Form.count', 1 do | |
106 | 106 | post :create, :profile => profile.identifier, |
107 | 107 | :form => { |
108 | 108 | :name => 'My Form', |
... | ... | @@ -139,7 +139,7 @@ class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase |
139 | 139 | :type => 'CustomFormsPlugin::TextField', |
140 | 140 | :position => '1' |
141 | 141 | } |
142 | - assert_difference CustomFormsPlugin::Form, :count, 1 do | |
142 | + assert_difference 'CustomFormsPlugin::Form.count', 1 do | |
143 | 143 | post :create, :profile => profile.identifier, |
144 | 144 | :form => { |
145 | 145 | :name => 'My Form', |
... | ... | @@ -195,26 +195,26 @@ class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase |
195 | 195 | |
196 | 196 | answer = CustomFormsPlugin::Answer.create!(:value => 'example', :field => field) |
197 | 197 | |
198 | - sub1 = CustomFormsPlugin::Submission.create!(:author_name => "john", :author_email => 'john@example.com', :form => form) | |
198 | + sub1 = create(CustomFormsPlugin::Submission, :author_name => "john", :author_email => 'john@example.com', :form => form) | |
199 | 199 | sub1.answers << answer |
200 | 200 | |
201 | 201 | bob = create_user('bob').person |
202 | 202 | sub2 = CustomFormsPlugin::Submission.create!(:profile => bob, :form => form) |
203 | 203 | |
204 | 204 | get :submissions, :profile => profile.identifier, :id => form.id, :format => 'csv' |
205 | - assert_equal @response.content_type, 'text/csv' | |
206 | - assert_equal @response.body.split("\n")[0], 'Timestamp,Name,Email,Title' | |
207 | - assert_equal @response.body.split("\n")[1], "#{sub1.updated_at.strftime('%Y/%m/%d %T %Z')},john,john@example.com,example" | |
208 | - assert_equal @response.body.split("\n")[2], "#{sub2.updated_at.strftime('%Y/%m/%d %T %Z')},bob,#{bob.email},\"\"" | |
205 | + assert_equal 'text/csv', @response.content_type | |
206 | + assert_equal 'Timestamp,Name,Email,Title', @response.body.split("\n")[0] | |
207 | + assert_equal "#{sub1.updated_at.strftime('%Y/%m/%d %T %Z')},john,john@example.com,example", @response.body.split("\n")[1] | |
208 | + assert_equal "#{sub2.updated_at.strftime('%Y/%m/%d %T %Z')},bob,#{bob.email},\"\"", @response.body.split("\n")[2] | |
209 | 209 | end |
210 | 210 | |
211 | 211 | should 'order submissions by name or time' do |
212 | 212 | form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software') |
213 | 213 | field = CustomFormsPlugin::TextField.create!(:name => "Title") |
214 | 214 | form.fields << field |
215 | - sub1 = CustomFormsPlugin::Submission.create!(:author_name => "john", :author_email => 'john@example.com', :form => form) | |
215 | + sub1 = create(CustomFormsPlugin::Submission, :author_name => "john", :author_email => 'john@example.com', :form => form) | |
216 | 216 | bob = create_user('bob').person |
217 | - sub2 = CustomFormsPlugin::Submission.create!(:profile => bob, :form => form) | |
217 | + sub2 = create(CustomFormsPlugin::Submission, :profile => bob, :form => form) | |
218 | 218 | |
219 | 219 | get :submissions, :profile => profile.identifier, :id => form.id, :sort_by => 'time' |
220 | 220 | assert_not_nil assigns(:sort_by) | ... | ... |
plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb
... | ... | @@ -22,7 +22,7 @@ class CustomFormsPluginProfileControllerTest < ActionController::TestCase |
22 | 22 | field1 = CustomFormsPlugin::TextField.create(:name => 'Name', :form => form, :mandatory => true) |
23 | 23 | field2 = CustomFormsPlugin::TextField.create(:name => 'License', :form => form) |
24 | 24 | |
25 | - assert_difference CustomFormsPlugin::Submission, :count, 1 do | |
25 | + assert_difference 'CustomFormsPlugin::Submission.count', 1 do | |
26 | 26 | post :show, :profile => profile.identifier, :id => form.id, :submission => {field1.id.to_s => 'Noosfero', field2.id.to_s => 'GPL'} |
27 | 27 | end |
28 | 28 | assert !session[:notice].include?('not saved') | ... | ... |
plugins/custom_forms/test/unit/custom_forms_plugin/answer_test.rb
... | ... | @@ -4,13 +4,13 @@ class CustomFormsPlugin::AnswerTest < ActiveSupport::TestCase |
4 | 4 | should 'validates presence of field' do |
5 | 5 | answer = CustomFormsPlugin::Answer.new |
6 | 6 | answer.valid? |
7 | - assert answer.errors.invalid?(:field) | |
7 | + assert answer.errors.include?(:field) | |
8 | 8 | |
9 | 9 | form = CustomFormsPlugin::Form.create!(:name => 'Free Software', :profile => fast_create(Profile)) |
10 | 10 | field = CustomFormsPlugin::Field.create!(:name => 'License', :form => form) |
11 | 11 | answer.field = field |
12 | 12 | answer.valid? |
13 | - assert !answer.errors.invalid?(:field) | |
13 | + assert !answer.errors.include?(:field) | |
14 | 14 | end |
15 | 15 | |
16 | 16 | should 'belong to a submission' do |
... | ... | @@ -27,11 +27,11 @@ class CustomFormsPlugin::AnswerTest < ActiveSupport::TestCase |
27 | 27 | field = CustomFormsPlugin::Field.create!(:name => 'License', :form => form, :mandatory => true) |
28 | 28 | answer = CustomFormsPlugin::Answer.new(:field => field) |
29 | 29 | answer.valid? |
30 | - assert answer.errors.invalid?(:value) | |
30 | + assert answer.errors.include?(:value) | |
31 | 31 | |
32 | 32 | answer.value = "GPL" |
33 | 33 | answer.valid? |
34 | - assert !answer.errors.invalid?(:value) | |
34 | + assert !answer.errors.include?(:value) | |
35 | 35 | end |
36 | 36 | |
37 | 37 | should 'make string representation show answers' do | ... | ... |
plugins/custom_forms/test/unit/custom_forms_plugin/field_test.rb
... | ... | @@ -27,7 +27,7 @@ class CustomFormsPlugin::FieldTest < ActiveSupport::TestCase |
27 | 27 | license_field = CustomFormsPlugin::Field.create!(:name => 'License', :form => form) |
28 | 28 | url_field = CustomFormsPlugin::Field.create!(:name => 'URL', :form => form) |
29 | 29 | |
30 | - assert_no_difference CustomFormsPlugin::Form, :count do | |
30 | + assert_no_difference 'CustomFormsPlugin::Form.count' do | |
31 | 31 | url_field.destroy |
32 | 32 | end |
33 | 33 | assert_equal form.fields, [license_field] | ... | ... |
plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb
... | ... | @@ -4,14 +4,14 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase |
4 | 4 | should 'validates presence of a profile and a name' do |
5 | 5 | form = CustomFormsPlugin::Form.new |
6 | 6 | form.valid? |
7 | - assert form.errors.invalid?(:profile) | |
8 | - assert form.errors.invalid?(:name) | |
7 | + assert form.errors.include?(:profile) | |
8 | + assert form.errors.include?(:name) | |
9 | 9 | |
10 | 10 | form.profile = fast_create(Profile) |
11 | 11 | form.name = 'Free Software' |
12 | 12 | form.valid? |
13 | - assert !form.errors.invalid?(:profile) | |
14 | - assert !form.errors.invalid?(:name) | |
13 | + assert !form.errors.include?(:profile) | |
14 | + assert !form.errors.include?(:name) | |
15 | 15 | end |
16 | 16 | |
17 | 17 | should 'have many fields including fields subclasses' do |
... | ... | @@ -46,11 +46,11 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase |
46 | 46 | CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software') |
47 | 47 | form = CustomFormsPlugin::Form.new(:profile => profile, :name => 'Free Software') |
48 | 48 | form.valid? |
49 | - assert form.errors.invalid?(:slug) | |
49 | + assert form.errors.include?(:slug) | |
50 | 50 | |
51 | 51 | form.profile = another_profile |
52 | 52 | form.valid? |
53 | - assert !form.errors.invalid?(:slug) | |
53 | + assert !form.errors.include?(:slug) | |
54 | 54 | end |
55 | 55 | |
56 | 56 | should 'validate the difference between ending and beginning is positive' do |
... | ... | @@ -60,11 +60,11 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase |
60 | 60 | form.begining = Time.now |
61 | 61 | form.ending = Time.now + 1.day |
62 | 62 | assert form.valid? |
63 | - assert !form.errors.invalid?(:base) | |
63 | + assert !form.errors.include?(:base) | |
64 | 64 | |
65 | 65 | form.ending = Time.now - 2.day |
66 | 66 | assert !form.valid? |
67 | - assert form.errors.invalid?(:base) | |
67 | + assert form.errors.include?(:base) | |
68 | 68 | end |
69 | 69 | |
70 | 70 | should 'define form expiration' do |
... | ... | @@ -108,38 +108,38 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase |
108 | 108 | should 'validates format of access' do |
109 | 109 | form = CustomFormsPlugin::Form.new |
110 | 110 | form.valid? |
111 | - assert !form.errors.invalid?(:access) | |
111 | + assert !form.errors.include?(:access) | |
112 | 112 | |
113 | 113 | form.access = 'bli' |
114 | 114 | form.valid? |
115 | - assert form.errors.invalid?(:access) | |
115 | + assert form.errors.include?(:access) | |
116 | 116 | |
117 | 117 | form.access = 'logged' |
118 | 118 | form.valid? |
119 | - assert !form.errors.invalid?(:access) | |
119 | + assert !form.errors.include?(:access) | |
120 | 120 | |
121 | 121 | form.access = 'associated' |
122 | 122 | form.valid? |
123 | - assert !form.errors.invalid?(:access) | |
123 | + assert !form.errors.include?(:access) | |
124 | 124 | |
125 | 125 | form.access = {:bli => 1} |
126 | 126 | form.valid? |
127 | - assert form.errors.invalid?(:access) | |
127 | + assert form.errors.include?(:access) | |
128 | 128 | |
129 | 129 | form.access = 999 |
130 | 130 | form.valid? |
131 | - assert form.errors.invalid?(:access) | |
131 | + assert form.errors.include?(:access) | |
132 | 132 | |
133 | 133 | p1 = fast_create(Profile) |
134 | 134 | form.access = p1.id |
135 | 135 | form.valid? |
136 | - assert !form.errors.invalid?(:access) | |
136 | + assert !form.errors.include?(:access) | |
137 | 137 | |
138 | 138 | p2 = fast_create(Profile) |
139 | 139 | p3 = fast_create(Profile) |
140 | 140 | form.access = [p1,p2,p3].map(&:id) |
141 | 141 | form.valid? |
142 | - assert !form.errors.invalid?(:access) | |
142 | + assert !form.errors.include?(:access) | |
143 | 143 | end |
144 | 144 | |
145 | 145 | should 'defines who is able to access the form' do |
... | ... | @@ -173,7 +173,7 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase |
173 | 173 | assert form.accessible_to(owner) |
174 | 174 | end |
175 | 175 | |
176 | - should 'have a named_scope that retrieve forms from a profile' do | |
176 | + should 'have a scope that retrieve forms from a profile' do | |
177 | 177 | profile = fast_create(Profile) |
178 | 178 | another_profile = fast_create(Profile) |
179 | 179 | f1 = CustomFormsPlugin::Form.create!(:name => 'Free Software', :profile => profile) |
... | ... | @@ -181,20 +181,20 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase |
181 | 181 | f3 = CustomFormsPlugin::Form.create!(:name => 'Free Software', :profile => another_profile) |
182 | 182 | scope = CustomFormsPlugin::Form.from(profile) |
183 | 183 | |
184 | - assert_equal ActiveRecord::NamedScope::Scope, scope.class | |
184 | + assert_equal ActiveRecord::Relation, scope.class | |
185 | 185 | assert_includes scope, f1 |
186 | 186 | assert_includes scope, f2 |
187 | 187 | assert_not_includes scope, f3 |
188 | 188 | end |
189 | 189 | |
190 | - should 'have a named_scope that retrieves all forms that are triggered on membership' do | |
190 | + should 'have a scope that retrieves all forms that are triggered on membership' do | |
191 | 191 | profile = fast_create(Profile) |
192 | 192 | f1 = CustomFormsPlugin::Form.create!(:name => 'On membership 1', :profile => profile, :on_membership => true) |
193 | 193 | f2 = CustomFormsPlugin::Form.create!(:name => 'On membership 2', :profile => profile, :on_membership => true) |
194 | 194 | f3 = CustomFormsPlugin::Form.create!(:name => 'Not on memberhsip', :profile => profile, :on_membership => false) |
195 | 195 | scope = CustomFormsPlugin::Form.from(profile).on_memberships |
196 | 196 | |
197 | - assert_equal ActiveRecord::NamedScope::Scope, scope.class | |
197 | + assert_equal ActiveRecord::Relation, scope.class | |
198 | 198 | assert_includes scope, f1 |
199 | 199 | assert_includes scope, f2 |
200 | 200 | assert_not_includes scope, f3 |
... | ... | @@ -205,7 +205,7 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase |
205 | 205 | license_field = CustomFormsPlugin::Field.create!(:name => 'License', :form => form) |
206 | 206 | url_field = CustomFormsPlugin::Field.create!(:name => 'URL', :form => form) |
207 | 207 | |
208 | - assert_difference CustomFormsPlugin::Field, :count, -2 do | |
208 | + assert_difference 'CustomFormsPlugin::Field.count', -2 do | |
209 | 209 | form.destroy |
210 | 210 | end |
211 | 211 | end |
... | ... | @@ -218,14 +218,14 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase |
218 | 218 | assert_equal form.fields, [url_field, license_field] |
219 | 219 | end |
220 | 220 | |
221 | - should 'have a named_scope that retrieves all forms required for membership' do | |
221 | + should 'have a scope that retrieves all forms required for membership' do | |
222 | 222 | profile = fast_create(Profile) |
223 | 223 | f1 = CustomFormsPlugin::Form.create!(:name => 'For admission 1', :profile => profile, :for_admission => true) |
224 | 224 | f2 = CustomFormsPlugin::Form.create!(:name => 'For admission 2', :profile => profile, :for_admission => true) |
225 | 225 | f3 = CustomFormsPlugin::Form.create!(:name => 'Not for admission', :profile => profile, :for_admission => false) |
226 | 226 | scope = CustomFormsPlugin::Form.from(profile).for_admissions |
227 | 227 | |
228 | - assert_equal ActiveRecord::NamedScope::Scope, scope.class | |
228 | + assert_equal ActiveRecord::Relation, scope.class | |
229 | 229 | assert_includes scope, f1 |
230 | 230 | assert_includes scope, f2 |
231 | 231 | assert_not_includes scope, f3 |
... | ... | @@ -237,7 +237,7 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase |
237 | 237 | f2 = CustomFormsPlugin::Form.create!(:name => 'For admission', :profile => profile, :on_membership => true, :for_admission => true) |
238 | 238 | scope = CustomFormsPlugin::Form.from(profile).on_memberships |
239 | 239 | |
240 | - assert_equal ActiveRecord::NamedScope::Scope, scope.class | |
240 | + assert_equal ActiveRecord::Relation, scope.class | |
241 | 241 | assert_includes scope, f1 |
242 | 242 | assert_not_includes scope, f2 |
243 | 243 | end | ... | ... |
plugins/custom_forms/test/unit/custom_forms_plugin/membership_survey_test.rb
... | ... | @@ -4,11 +4,11 @@ class CustomFormsPlugin::MembershipSurveyTest < ActiveSupport::TestCase |
4 | 4 | should 'validates presence of form_id' do |
5 | 5 | task = CustomFormsPlugin::MembershipSurvey.new |
6 | 6 | task.valid? |
7 | - assert task.errors.invalid?(:form_id) | |
7 | + assert task.errors.include?(:form_id) | |
8 | 8 | |
9 | 9 | task.form_id = 1 |
10 | 10 | task.valid? |
11 | - assert !task.errors.invalid?(:form_id) | |
11 | + assert !task.errors.include?(:form_id) | |
12 | 12 | end |
13 | 13 | |
14 | 14 | should 'create submission with answers on perform' do |
... | ... | @@ -18,7 +18,7 @@ class CustomFormsPlugin::MembershipSurveyTest < ActiveSupport::TestCase |
18 | 18 | field = CustomFormsPlugin::Field.create!(:name => 'Name', :form => form) |
19 | 19 | task = CustomFormsPlugin::MembershipSurvey.create!(:form_id => form.id, :submission => {field.id.to_s => 'Jack'}, :target => person, :requestor => profile) |
20 | 20 | |
21 | - assert_difference CustomFormsPlugin::Submission, :count, 1 do | |
21 | + assert_difference 'CustomFormsPlugin::Submission.count', 1 do | |
22 | 22 | task.finish |
23 | 23 | end |
24 | 24 | |
... | ... | @@ -29,7 +29,7 @@ class CustomFormsPlugin::MembershipSurveyTest < ActiveSupport::TestCase |
29 | 29 | assert_equal answer.value, 'Jack' |
30 | 30 | end |
31 | 31 | |
32 | - should 'have a named_scope that retrieves all tasks requested by profile' do | |
32 | + should 'have a scope that retrieves all tasks requested by profile' do | |
33 | 33 | profile = fast_create(Profile) |
34 | 34 | person = fast_create(Person) |
35 | 35 | form = CustomFormsPlugin::Form.create!(:name => 'Simple Form', :profile => profile) |
... | ... | @@ -37,7 +37,7 @@ class CustomFormsPlugin::MembershipSurveyTest < ActiveSupport::TestCase |
37 | 37 | task2 = CustomFormsPlugin::MembershipSurvey.create!(:form_id => form.id, :target => person, :requestor => fast_create(Profile)) |
38 | 38 | scope = CustomFormsPlugin::MembershipSurvey.from(profile) |
39 | 39 | |
40 | - assert_equal ActiveRecord::NamedScope::Scope, scope.class | |
40 | + assert_equal ActiveRecord::Relation, scope.class | |
41 | 41 | assert_includes scope, task1 |
42 | 42 | assert_not_includes scope, task2 |
43 | 43 | end | ... | ... |
plugins/custom_forms/test/unit/custom_forms_plugin/submission_test.rb
... | ... | @@ -4,12 +4,12 @@ class CustomFormsPlugin::SubmissionTest < ActiveSupport::TestCase |
4 | 4 | should 'validates presence of form' do |
5 | 5 | submission = CustomFormsPlugin::Submission.new |
6 | 6 | submission.valid? |
7 | - assert submission.errors.invalid?(:form) | |
7 | + assert submission.errors.include?(:form) | |
8 | 8 | |
9 | 9 | form = CustomFormsPlugin::Form.create!(:name => 'Free Software', :profile => fast_create(Profile)) |
10 | 10 | submission.form = form |
11 | 11 | submission.valid? |
12 | - assert !submission.errors.invalid?(:form) | |
12 | + assert !submission.errors.include?(:form) | |
13 | 13 | end |
14 | 14 | |
15 | 15 | should 'belong to a profile' do |
... | ... | @@ -22,14 +22,14 @@ class CustomFormsPlugin::SubmissionTest < ActiveSupport::TestCase |
22 | 22 | should 'require presence of author name and email if profile is nil' do |
23 | 23 | submission = CustomFormsPlugin::Submission.new |
24 | 24 | submission.valid? |
25 | - assert submission.errors.invalid?(:author_name) | |
26 | - assert submission.errors.invalid?(:author_email) | |
25 | + assert submission.errors.include?(:author_name) | |
26 | + assert submission.errors.include?(:author_email) | |
27 | 27 | |
28 | 28 | submission.author_name = 'Jack Sparrow' |
29 | 29 | submission.author_email = 'jack@black-pearl.com' |
30 | 30 | submission.valid? |
31 | - assert !submission.errors.invalid?(:author_name) | |
32 | - assert !submission.errors.invalid?(:author_email) | |
31 | + assert !submission.errors.include?(:author_name) | |
32 | + assert !submission.errors.include?(:author_email) | |
33 | 33 | end |
34 | 34 | |
35 | 35 | should 'have answers' do | ... | ... |
plugins/custom_forms/test/unit/ext/role_assingment_test.rb
... | ... | @@ -10,7 +10,7 @@ class RoleAssignmentsTest < ActiveSupport::TestCase |
10 | 10 | f2 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 2', :on_membership => true) |
11 | 11 | f3 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 3', :on_membership => false) |
12 | 12 | |
13 | - assert_difference CustomFormsPlugin::MembershipSurvey, :count, 2 do | |
13 | + assert_difference 'CustomFormsPlugin::MembershipSurvey.count', 2 do | |
14 | 14 | organization.add_member(person) |
15 | 15 | end |
16 | 16 | end |
... | ... | @@ -22,7 +22,7 @@ class RoleAssignmentsTest < ActiveSupport::TestCase |
22 | 22 | person = fast_create(Person) |
23 | 23 | form = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form', :on_membership => true, :access => 'associated') |
24 | 24 | |
25 | - assert_difference CustomFormsPlugin::MembershipSurvey, :count, 1 do | |
25 | + assert_difference 'CustomFormsPlugin::MembershipSurvey.count', 1 do | |
26 | 26 | organization.add_member(person) |
27 | 27 | end |
28 | 28 | end |
... | ... | @@ -35,14 +35,14 @@ class RoleAssignmentsTest < ActiveSupport::TestCase |
35 | 35 | form1 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 1', :on_membership => true) |
36 | 36 | organization.add_member(person) |
37 | 37 | |
38 | - assert_difference CustomFormsPlugin::MembershipSurvey.pending, :count, -1 do | |
38 | + assert_difference 'CustomFormsPlugin::MembershipSurvey.pending.count', -1 do | |
39 | 39 | organization.remove_member(person) |
40 | 40 | end |
41 | 41 | |
42 | 42 | form2 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 2', :for_admission => true) |
43 | 43 | organization.add_member(person) |
44 | 44 | |
45 | - assert_difference CustomFormsPlugin::AdmissionSurvey.pending, :count, -1 do | |
45 | + assert_difference 'CustomFormsPlugin::AdmissionSurvey.pending.count', -1 do | |
46 | 46 | organization.remove_member(person) |
47 | 47 | end |
48 | 48 | |
... | ... | @@ -50,7 +50,7 @@ class RoleAssignmentsTest < ActiveSupport::TestCase |
50 | 50 | tasks = CustomFormsPlugin::MembershipSurvey.all.last(2) |
51 | 51 | tasks.each {|t| t.status = Task::Status::FINISHED } |
52 | 52 | tasks.each {|t| t.save! } |
53 | - assert_no_difference CustomFormsPlugin::MembershipSurvey.finished, :count do | |
53 | + assert_no_difference 'CustomFormsPlugin::MembershipSurvey.finished.count' do | |
54 | 54 | organization.remove_member(person) |
55 | 55 | end |
56 | 56 | end |
... | ... | @@ -64,7 +64,7 @@ class RoleAssignmentsTest < ActiveSupport::TestCase |
64 | 64 | f2 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 2', :for_admission => true) |
65 | 65 | f3 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 3', :for_admission => false) |
66 | 66 | |
67 | - assert_difference CustomFormsPlugin::AdmissionSurvey, :count, 2 do | |
67 | + assert_difference 'CustomFormsPlugin::AdmissionSurvey.count', 2 do | |
68 | 68 | organization.add_member(person) |
69 | 69 | end |
70 | 70 | assert !organization.members.include?(person) | ... | ... |
plugins/custom_forms/views/custom_forms_plugin_myprofile/_field.html.erb
... | ... | @@ -12,7 +12,7 @@ |
12 | 12 | <%= f.hidden_field(:position) %> |
13 | 13 | |
14 | 14 | <%= f.hidden_field :_destroy, :class => 'destroy-field' %> |
15 | - <%= button_to_function :delete, _('Remove field'), "customFormsPlugin.removeFieldBox(this, #{_('Are you sure you want to remove this field?').to_json})" %> | |
15 | + <%= button_to_function :delete, _('Remove field'), "customFormsPlugin.removeFieldBox(this, #{j _('Are you sure you want to remove this field?').to_json})" %> | |
16 | 16 | <%= yield %> |
17 | 17 | </div> |
18 | 18 | </fieldset> | ... | ... |
plugins/custom_forms/views/custom_forms_plugin_myprofile/_form.html.erb
1 | 1 | <% self.extend(CustomFormsPlugin::Helper) %> |
2 | 2 | <%= render :file => 'shared/tiny_mce', :locals => {:mode => 'simple'} %> |
3 | 3 | |
4 | -<%= f.error_messages %> | |
4 | +<%= error_messages_for :form %> | |
5 | 5 | <%= required labelled_form_field _('Name'), f.text_field(:name) %> |
6 | 6 | <%= labelled_form_field(_('What is the time limit for this form to be filled?'), ( |
7 | 7 | date_range_field('form[begining]', 'form[ending]', @form.begining, @form.ending, |
... | ... | @@ -31,8 +31,8 @@ |
31 | 31 | </ul> |
32 | 32 | |
33 | 33 | <div class="addition-buttons"> |
34 | - <%= button(:add, _('Add a new text field'), '#', :onclick => "customFormsPlugin.addFields(this, 'fields', #{html_for_field(f, :fields, CustomFormsPlugin::TextField).to_json}); return false")%> | |
35 | - <%= button(:add, _('Add a new select field'), '#', :onclick => "customFormsPlugin.addFields(this, 'fields', #{html_for_field(f, :fields, CustomFormsPlugin::SelectField).to_json}); return false")%> | |
34 | + <%= button(:add, _('Add a new text field'), '#', :onclick => "customFormsPlugin.addFields(this, 'fields', #{j html_for_field(f, :fields, CustomFormsPlugin::TextField).to_json}); return false")%> | |
35 | + <%= button(:add, _('Add a new select field'), '#', :onclick => "customFormsPlugin.addFields(this, 'fields', #{j html_for_field(f, :fields, CustomFormsPlugin::SelectField).to_json}); return false")%> | |
36 | 36 | </div> |
37 | 37 | |
38 | 38 | <% button_bar do %> | ... | ... |
plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_alternative.html.erb
... | ... | @@ -7,6 +7,6 @@ |
7 | 7 | |
8 | 8 | <td> |
9 | 9 | <%= f.hidden_field :_destroy, :class => 'destroy-field' %> |
10 | - <%= button_to_function_without_text :remove, _('Remove alternative'), "customFormsPlugin.removeAlternative(this, #{_('Are you sure you want to remove this alternative?').to_json})", :class => 'remove-field', :title => _('Remove alternative') %> | |
10 | + <%= button_to_function_without_text :remove, _('Remove alternative'), "customFormsPlugin.removeAlternative(this, #{j _('Are you sure you want to remove this alternative?').to_json})", :class => 'remove-field', :title => _('Remove alternative') %> | |
11 | 11 | </td> |
12 | 12 | </tr> | ... | ... |
plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_select_field.html.erb
1 | -<% render :layout => 'field', :locals => { :f => f } do %> | |
1 | +<%= render :layout => 'field', :locals => { :f => f } do %> | |
2 | 2 | <div class="field-select-type"> |
3 | 3 | <%= _('Type:') %> |
4 | 4 | <%= f.radio_button(:select_field_type, 'radio') %> |
... | ... | @@ -22,7 +22,7 @@ |
22 | 22 | <tfoot> |
23 | 23 | <tr class="addition-buttons"> |
24 | 24 | <td colspan="3"> |
25 | - <%= button(:add, _('Add a new alternative'), '#', :onclick => "customFormsPlugin.addFields(this, 'alternatives', #{html_for_field(f, :alternatives, CustomFormsPlugin::Alternative).to_json}); return false") %> | |
25 | + <%= button(:add, _('Add a new alternative'), '#', :onclick => "customFormsPlugin.addFields(this, 'alternatives', #{j html_for_field(f, :alternatives, CustomFormsPlugin::Alternative).to_json}); return false") %> | |
26 | 26 | </td> |
27 | 27 | </tr> |
28 | 28 | </tfoot> | ... | ... |
plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_text_field.html.erb
plugins/custom_forms/views/custom_forms_plugin_myprofile/edit.html.erb
1 | 1 | <h1><%= _('Edit form') %></h1> |
2 | 2 | |
3 | -<%= form_for :form, @form, :url => { :action => 'update', :id => params[:id] } do |f| %> | |
3 | +<%= form_for @form, :as => :form, :url => { :action => 'update', :id => params[:id] } do |f| %> | |
4 | 4 | <%= render :partial => 'form', :locals => {:f => f} %> |
5 | 5 | <% end %> | ... | ... |
plugins/custom_forms/views/custom_forms_plugin_myprofile/new.html.erb
1 | 1 | <h1><%= _('New form') %></h1> |
2 | 2 | |
3 | -<%= form_for :form, @form, :url => { :action => 'create', :id => params[:id] } do |f| %> | |
3 | +<%= form_for @form, :as => :form, :url => { :action => 'create', :id => params[:id] } do |f| %> | |
4 | 4 | <%= render :partial => 'form', :locals => {:f => f} %> |
5 | 5 | <% end %> | ... | ... |
plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb
... | ... | @@ -12,7 +12,7 @@ |
12 | 12 | |
13 | 13 | <%= error_messages_for :submission %> |
14 | 14 | |
15 | - <%= form_for :submission, @submission do |f| %> | |
15 | + <%= form_for :submission do |f| %> | |
16 | 16 | <% if !user %> |
17 | 17 | <%= required labelled_form_field _('Author name'), text_field_tag(:author_name, @submission.author_name) %> |
18 | 18 | <%= required labelled_form_field _('Author email'), text_field_tag(:author_email, @submission.author_email) %> | ... | ... |