Fix syntax errors for upgrade of Rails version

This commit is contained in:
Jyri-Petteri Paloposki 2022-01-04 01:18:13 +02:00
parent 7f567862d7
commit 86e36b07a6
9 changed files with 21 additions and 21 deletions

View file

@ -83,7 +83,7 @@ class ContextsController < ApplicationController
end end
format.xml do format.xml do
if @context.new_record? if @context.new_record?
render_failure @context.errors.to_xml.html_safe, 409 render_failure @context.errors.full_messages.to_xml(root: "errors", skip_types: true).html_safe, 409
else else
head :created, :location => context_url(@context) head :created, :location => context_url(@context)
end end

View file

@ -186,7 +186,7 @@ class ProjectsController < ApplicationController
end end
format.xml do format.xml do
if @project.new_record? if @project.new_record?
render_failure @project.errors.to_xml.html_safe, 409 render_failure @project.errors.full_messages.to_xml(root: "errors", skip_types: true).html_safe, 409
else else
head :created, :location => project_url(@project), :text => @project.id head :created, :location => project_url(@project), :text => @project.id
end end

View file

@ -154,7 +154,7 @@ class TodosController < ApplicationController
if @saved if @saved
head :created, :location => todo_url(@todo) head :created, :location => todo_url(@todo)
else else
render_failure @todo.errors.to_xml.html_safe, 409 render_failure @todo.errors.full_messages.to_xml(root: "errors", skip_types: true).html_safe, 409
end end
end end
end end
@ -438,7 +438,7 @@ class TodosController < ApplicationController
rescue ActiveRecord::RecordInvalid => exception rescue ActiveRecord::RecordInvalid => exception
record = exception.record record = exception.record
if record.is_a?(Dependency) if record.is_a?(Dependency)
record.errors.each { |key, value| @todo.errors[key] << value } record.errors.each { |key, value| @todo.errors.add(key, value) }
end end
@saved = false @saved = false
end end
@ -1192,7 +1192,7 @@ end
begin begin
parse_date_per_user_prefs(date) parse_date_per_user_prefs(date)
rescue rescue
@todo.errors[:base] << error_msg @todo.errors.add(:base, error_msg)
end end
end end

View file

@ -125,7 +125,7 @@ class UsersController < ApplicationController
unless user.new_record? unless user.new_record?
render :body => t('users.user_created'), :status => 200 render :body => t('users.user_created'), :status => 200
else else
render_failure user.errors.to_xml, 409 render_failure user.errors.full_messages.to_xml(root: "errors", skip_types: true), 409
end end
return return
end end

View file

@ -80,11 +80,11 @@ module RecurringTodos
end end
def validate_not_blank(object, msg) def validate_not_blank(object, msg)
errors[:base] << msg if object.blank? errors.add(:base, msg) if object.blank?
end end
def validate_not_nil(object, msg) def validate_not_nil(object, msg)
errors[:base] << msg if object.nil? errors.add(:base, msg) if object.nil?
end end
def validate def validate
@ -100,7 +100,7 @@ module RecurringTodos
when "ends_on_end_date" when "ends_on_end_date"
validate_not_blank(end_date, "The end date needs to be filled in for 'Ends on'") validate_not_blank(end_date, "The end date needs to be filled in for 'Ends on'")
else else
errors[:base] << "The end of the recurrence is not selected" unless ends_on == "no_end_date" errors.add(:base, "The end of the recurrence is not selected") unless ends_on == "no_end_date"
end end
end end
@ -113,7 +113,7 @@ module RecurringTodos
validate_not_nil(show_always?, "Please select when to show the action") validate_not_nil(show_always?, "Please select when to show the action")
validate_not_blank(show_from_delta, "Please fill in the number of days to show the todo before the due date") unless show_always? validate_not_blank(show_from_delta, "Please fill in the number of days to show the todo before the due date") unless show_always?
else else
errors[:base] << "Unexpected value of recurrence target selector '#{target}'" errors.add(:base, "Unexpected value of recurrence target selector '#{target}'")
end end
end end

View file

@ -24,7 +24,7 @@ module RecurringTodos
def validate def validate
super super
errors[:base] << "Every other nth day may not be empty for this daily recurrence setting" if (!only_work_days?) && every_x_days.blank? errors.add(:base, "Every other nth day may not be empty for this daily recurrence setting") if (!only_work_days?) && every_x_days.blank?
end end
def get_next_date(previous) def get_next_date(previous)

View file

@ -30,7 +30,7 @@ module RecurringTodos
super super
validate_not_blank(every_x_week, "Every other nth week may not be empty for weekly recurrence setting") validate_not_blank(every_x_week, "Every other nth week may not be empty for weekly recurrence setting")
something_set = %w{ sunday monday tuesday wednesday thursday friday saturday }.inject(false) { |set, day| set || send("on_#{day}") } something_set = %w{ sunday monday tuesday wednesday thursday friday saturday }.inject(false) { |set, day| set || send("on_#{day}") }
errors[:base] << "You must specify at least one day on which the todo recurs" unless something_set errors.add(:base, "You must specify at least one day on which the todo recurs") unless something_set
end end
def get_next_date(previous) def get_next_date(previous)

View file

@ -1,7 +1,7 @@
class ProjectsContextsRemoveNotNullFromPosition < ActiveRecord::Migration[5.2] class ProjectsContextsRemoveNotNullFromPosition < ActiveRecord::Migration[5.2]
def self.up def self.up
change_column :projects, :position, :integer, {:null => true, :default => nil} change_column :projects, :position, :integer, :null => true, :default => nil
change_column :contexts, :position, :integer, {:null => true, :default => nil} change_column :contexts, :position, :integer, :null => true, :default => nil
end end
def self.down def self.down
@ -10,13 +10,13 @@ class ProjectsContextsRemoveNotNullFromPosition < ActiveRecord::Migration[5.2]
project.position = 0 if !project.position? project.position = 0 if !project.position?
project.save project.save
end end
change_column :projects, :position, :integer, {:null => false, :default => nil} change_column :projects, :position, :integer, :null => false, :default => nil
@contexts = Context.find(:all) @contexts = Context.find(:all)
@contexts.each do |context| @contexts.each do |context|
context.position = 0 if !context.position? context.position = 0 if !context.position?
context.save context.save
end end
change_column :contexts, :position, :integer, {:null => false, :default => nil} change_column :contexts, :position, :integer, :null => false, :default => nil
end end
end end

View file

@ -102,7 +102,7 @@ class TodoTest < ActiveSupport::TestCase
@not_completed2 @not_completed2
assert_equal :active, @not_completed2.aasm.current_state assert_equal :active, @not_completed2.aasm.current_state
@not_completed2.show_from = Time.zone.now + 1.week @not_completed2.show_from = Time.zone.now + 1.week
assert @not_completed2.save, "should have saved successfully" + @not_completed2.errors.to_xml assert @not_completed2.save, "should have saved successfully " + @not_completed2.errors.full_messages.to_s
assert_equal :deferred, @not_completed2.aasm.current_state assert_equal :deferred, @not_completed2.aasm.current_state
end end
@ -112,14 +112,14 @@ class TodoTest < ActiveSupport::TestCase
todo.show_from = next_week todo.show_from = next_week
todo.context_id = 1 todo.context_id = 1
todo.description = 'foo' todo.description = 'foo'
assert todo.save, "should have saved successfully" + todo.errors.to_xml assert todo.save, "should have saved successfully" + todo.errors.full_messages.to_s
assert_equal :deferred, todo.aasm.current_state assert_equal :deferred, todo.aasm.current_state
end end
def test_create_a_new_deferred_todo_by_passing_attributes def test_create_a_new_deferred_todo_by_passing_attributes
user = users(:other_user) user = users(:other_user)
todo = user.todos.build(:show_from => next_week, :context_id => 1, :description => 'foo') todo = user.todos.build(:show_from => next_week, :context_id => 1, :description => 'foo')
assert todo.save, "should have saved successfully" + todo.errors.to_xml assert todo.save, "should have saved successfully " + todo.errors.full_messages.to_s
assert_equal :deferred, todo.aasm.current_state assert_equal :deferred, todo.aasm.current_state
end end
@ -551,7 +551,7 @@ class TodoTest < ActiveSupport::TestCase
new_path = attachment.file.path new_path = attachment.file.path
# then the attachment should be there # then the attachment should be there
assert File.exists?(new_path), "attachment should be on file system" assert File.exist?(new_path), "attachment should be on file system"
assert_equal 1, todo.attachments.reload.count, "should have one attachment" assert_equal 1, todo.attachments.reload.count, "should have one attachment"
# When I destroy the todo # When I destroy the todo
@ -559,7 +559,7 @@ class TodoTest < ActiveSupport::TestCase
# Then the attachement and file should nogt be there anymore # Then the attachement and file should nogt be there anymore
assert_equal 0, todo.user.attachments.reload.count assert_equal 0, todo.user.attachments.reload.count
assert !File.exists?(new_path), "attachment should not be on file system" assert !File.exist?(new_path), "attachment should not be on file system"
end end
def test_destroying_action_activates_successors def test_destroying_action_activates_successors