Skip to content

Commit

Permalink
Use Time.now for auto accept / auto cleanup
Browse files Browse the repository at this point in the history
Active Record internally converts the time accept_at string to datetime
which means we can safely use Time.now (the produced request xml does
not change). Also the conversion and comparison of Time and DateTime is
still working after this change.

The change itself was needed / demanded by Rubocop:
  https://github.com/rubocop-hq/ruby-style-guide#date--time
  • Loading branch information
bgeuken authored and dmarcoux committed Nov 5, 2018
1 parent 0b442dd commit c926b74
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/api/app/jobs/project_create_auto_cleanup_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def perform
# defaults
User.current ||= User.find_by_login('Admin')
@cleanup_attribute = AttribType.find_by_namespace_and_name!('OBS', 'AutoCleanup')
@cleanup_time = DateTime.now + cleanup_days.days
@cleanup_time = Time.now + cleanup_days.days

Project.find_by_attribute_type(@cleanup_attribute).each do |prj|
autoclean_project(prj)
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/branch_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def create_branch_project
def add_autocleanup_attribute(tprj)
at = AttribType.find_by_namespace_and_name!('OBS', 'AutoCleanup')
a = Attrib.new(project: tprj, attrib_type: at)
a.values << AttribValue.new(value: (DateTime.now + @auto_cleanup.days), position: 1)
a.values << AttribValue.new(value: (Time.now + @auto_cleanup.days), position: 1)
a.save
end

Expand Down
4 changes: 2 additions & 2 deletions src/api/app/models/bs_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SaveError < APIError

ACTION_NOTIFY_LIMIT = 50

scope :to_accept_by_time, -> { where(state: ['new', 'review']).where('accept_at < ?', DateTime.now) }
scope :to_accept_by_time, -> { where(state: ['new', 'review']).where('accept_at < ?', Time.now) }
# Scopes for collections
scope :with_actions, -> { includes(:bs_request_actions).references(:bs_request_actions).distinct.order(priority: :asc, id: :desc) }
scope :with_involved_projects, ->(project_ids) { where(bs_request_actions: { target_project_id: project_ids }) }
Expand Down Expand Up @@ -227,7 +227,7 @@ def self.new_from_hash(hashed)
str = hashed.value('accept_at')
request.accept_at = DateTime.parse(str) if str
hashed.delete('accept_at')
raise SaveError, 'Auto accept time is in the past' if request.accept_at && request.accept_at < DateTime.now
raise SaveError, 'Auto accept time is in the past' if request.accept_at && request.accept_at < Time.now

# we do not support to import history anymore on purpose
# would be all fake, but means also history gets lost when
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/features/webui/requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
end

scenario 'when request auto_accept is in the future and not in a final state' do
bs_request.accept_at = DateTime.now + 1.day
bs_request.accept_at = Time.now + 1.day
bs_request.save
visit request_show_path(bs_request)
expect(page).
Expand Down

0 comments on commit c926b74

Please sign in to comment.