preserve created_at in page views from redis
fixes CNVS-5572 test-plan: - have page views enabled and processing through a redis queue - generate a new page view from a user with non-UTC time zone - process redis queue to persist page view - reload page view and check created_at; should equal the time the page view was created Change-Id: I8fa4da8f81d7f18815ef9223decea433e9a71172 Reviewed-on: https://gerrit.instructure.com/20171 Reviewed-by: Brian Palmer <brianp@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Clare Strong <clare@instructure.com> Product-Review: Jacob Fugal <jacob@instructure.com>
This commit is contained in:
parent
67660ed8f0
commit
3b80c364a5
|
@ -142,10 +142,16 @@ class PageView < ActiveRecord::Base
|
|||
raise(NotImplementedError, "find_every not implemented")
|
||||
end
|
||||
|
||||
def self.from_attributes(attrs)
|
||||
def self.from_attributes(attrs, new_record=false)
|
||||
@blank_template ||= columns.inject({}) { |h,c| h[c.name] = nil; h }
|
||||
shard = cassandra? ? Shard.default : Shard.current
|
||||
page_view = shard.activate{ instantiate(@blank_template.merge(attrs)) }
|
||||
page_view = shard.activate do
|
||||
if new_record
|
||||
new{ |pv| pv.send(:attributes=, attrs, false) }
|
||||
else
|
||||
instantiate(@blank_template.merge(attrs))
|
||||
end
|
||||
end
|
||||
page_view.page_view_method = :cassandra if cassandra?
|
||||
page_view
|
||||
end
|
||||
|
@ -269,8 +275,7 @@ class PageView < ActiveRecord::Base
|
|||
return unless page_view
|
||||
page_view.do_update(attrs)
|
||||
else
|
||||
page_view = self.from_attributes(attrs)
|
||||
page_view.instance_variable_set(:'@new_record', true)
|
||||
page_view = self.from_attributes(attrs, true)
|
||||
end
|
||||
page_view.save
|
||||
end
|
||||
|
@ -385,8 +390,7 @@ class PageView < ActiveRecord::Base
|
|||
false
|
||||
else
|
||||
# assumes PageView.cassandra? is true at this point
|
||||
page_view = PageView.from_attributes(attrs)
|
||||
page_view.instance_variable_set(:'@new_record', true)
|
||||
page_view = PageView.from_attributes(attrs, true)
|
||||
page_view.save!
|
||||
true
|
||||
end
|
||||
|
|
|
@ -267,6 +267,16 @@ describe PageView do
|
|||
PageView.count.should == 3
|
||||
end
|
||||
|
||||
it "should preserve timestamp" do
|
||||
Time.use_zone('Alaska') do
|
||||
pv = PageView.new{ |p| p.send(:attributes=, { :user => @user, :url => "http://test.one/", :session_id => "phony", :context => @course, :controller => 'courses', :action => 'show', :user_request => true, :render_time => 0.01, :user_agent => 'None', :account_id => Account.default.id, :request_id => "abcdef", :interaction_seconds => 5 }, false) }
|
||||
pv.store
|
||||
original_created_at = pv.created_at
|
||||
PageView.process_cache_queue
|
||||
pv.reload.created_at.to_i.should == original_created_at.to_i
|
||||
end
|
||||
end
|
||||
|
||||
describe "batch transaction" do
|
||||
self.use_transactional_fixtures = false
|
||||
it "should not fail the batch if one row fails" do
|
||||
|
|
Loading…
Reference in New Issue