end
end
end
- if @object.update_attributes @updates
+ if @object.update @updates
show
else
self.render_error status: 422
@new_resource_attrs ||= params[model_class.to_s.underscore.singularize]
@new_resource_attrs ||= {}
@object = @object.dup
- @object.update_attributes @new_resource_attrs
+ @object.update @new_resource_attrs
if not @new_resource_attrs[:name] and @object.respond_to? :name
if @object.name and @object.name != ''
@object.name = "Copy of #{@object.name}"
arv_coll.rm "."+p
end
- if @object.update_attributes manifest_text: arv_coll.manifest_text
+ if @object.update manifest_text: arv_coll.manifest_text
show
else
self.render_error status: 422
else
arv_coll.rename "./"+file_path, new_file_path
- if @object.update_attributes manifest_text: arv_coll.manifest_text
+ if @object.update manifest_text: arv_coll.manifest_text
show
else
self.render_error status: 422
@object.state = 'Final'
end
end
- @object.update_attributes! priority: 0
+ @object.update! priority: 0
if params[:return_to]
redirect_to params[:return_to]
else
# Object is owned by this project. Remove it from the project by
# changing owner to the current user.
begin
- item.update_attributes owner_uuid: current_user.uuid
+ item.update owner_uuid: current_user.uuid
@removed_uuids << item.uuid
rescue ArvadosApiClient::ApiErrorResponseException => e
if e.message.include? '_owner_uuid_'
updates = {}
updates[:name] = rename_to
updates[:owner_uuid] = current_user.uuid
- item.update_attributes updates
+ item.update updates
@removed_uuids << item.uuid
else
raise
end
while (objects = @object.contents).any?
objects.each do |object|
- object.update_attributes! owner_uuid: current_user.uuid
+ object.update! owner_uuid: current_user.uuid
end
end
if ArvadosBase::resource_class_for_uuid(@object.owner_uuid) == Group
self.name.underscore.pluralize.downcase
end
- def update_attributes raw_params={}
+ def update raw_params={}
assign_attributes(self.class.permit_attribute_params(raw_params))
save
end
- def update_attributes! raw_params={}
+ def update! raw_params={}
assign_attributes(self.class.permit_attribute_params(raw_params))
save!
end
<%
prefs = current_user.prefs
prefs[:getting_started_shown] = Time.now
- current_user.update_attributes prefs: prefs.to_json
+ current_user.update prefs: prefs.to_json
%>
<% end %>
# Go behind Workbench's back to expire the "active" token.
token = api_fixture('api_client_authorizations')['active']['api_token']
auth = ApiClientAuthorization.find(token)
- auth.update_attributes(expires_at: '1999-12-31T23:59:59Z')
+ auth.update(expires_at: '1999-12-31T23:59:59Z')
end
click_link "Subprojects"
wait_for_ajax
teardown do
use_token :admin do
@keep_services.each do |ks|
- KeepService.find(ks.uuid).update_attributes(ks.attributes)
+ KeepService.find(ks.uuid).update(ks.attributes)
end
end
testfiles.each do |filename, _|
need_selenium "to make file uploads work"
use_token :admin do
KeepService.where(service_type: 'proxy').first.
- update_attributes(service_ssl_flag: false)
+ update(service_ssl_flag: false)
end
visit page_with_token 'active', sandbox_path
find('.nav-tabs a', text: 'Upload').click
# Even if port 0 is a thing, surely nx.example.net won't
# respond
KeepService.where(service_type: 'proxy').first.
- update_attributes(service_host: 'nx.example.net',
+ update(service_host: 'nx.example.net',
service_port: 0)
end
visit page_with_token 'active', sandbox_path
end
time_block 'update(name-only)' do
manifest_text_length = c.manifest_text.length
- c.update_attributes name: 'renamed during test case'
+ c.update name: 'renamed during test case'
assert_equal c.manifest_text.length, manifest_text_length
end
time_block 'update' do
=> ["https://workbench.example.com/", Sat, 19 Apr 2014 03:35:12 UTC +00:00]
irb(main):002:0> <span class="userinput">include CurrentApiClient</span>
=> true
-irb(main):003:0> <span class="userinput">act_as_system_user do wb.update_attributes!(is_trusted: true) end</span>
+irb(main):003:0> <span class="userinput">act_as_system_user do wb.update!(is_trusted: true) end</span>
=> true
</code></pre>
</notextile>
attrs_to_update = resource_attrs.reject { |k,v|
[:kind, :etag, :href].index k
}
- @object.update_attributes! attrs_to_update
+ @object.update! attrs_to_update
show
end
attrs_to_update = resource_attrs.reject { |k, v|
[:kind, :etag, :href].index k
}.merge({async_permissions_update: true})
- @object.update_attributes!(attrs_to_update)
+ @object.update!(attrs_to_update)
@object.save!
render_accepted
else
attrs_to_update = resource_attrs.reject { |k,v|
[:kind, :etag, :href].index k
}
- @object.update_attributes!(attrs_to_update)
+ @object.update!(attrs_to_update)
@object.assign_slot if params[:assign_slot]
@object.save!
show
end
if needupdate.length > 0
begin
- u.update_attributes!(needupdate)
+ u.update!(needupdate)
rescue ActiveRecord::RecordInvalid
loginCluster = Rails.configuration.Login.LoginCluster
if u.uuid[0..4] == loginCluster && !needupdate[:username].nil?
if local_user.andand.uuid[0..4] == loginCluster && local_user.uuid != u.uuid
new_username = "#{needupdate[:username]}conflict#{rand(99999999)}"
Rails.logger.warn("cached username '#{needupdate[:username]}' collision with user '#{local_user.uuid}' - renaming to '#{new_username}' before retrying")
- local_user.update_attributes!({username: new_username})
+ local_user.update!({username: new_username})
retry
end
end
collect(&:head_uuid)
todo_uuids = required_uuids - signed_uuids
if todo_uuids.empty?
- @object.update_attributes is_active: true
+ @object.update is_active: true
logger.info "User #{@object.uuid} activated"
else
logger.warn "User #{@object.uuid} called users.activate " +
(remote_user_prefix == Rails.configuration.Login.LoginCluster or
Rails.configuration.Users.NewUsersAreActive or
Rails.configuration.RemoteClusters[remote_user_prefix].andand["ActivateUsers"])
- user.update_attributes!(is_active: true)
+ user.update!(is_active: true)
elsif user.is_active && !remote_user['is_active']
- user.update_attributes!(is_active: false)
+ user.update!(is_active: false)
end
if remote_user_prefix == Rails.configuration.Login.LoginCluster and
user.is_admin != remote_user['is_admin']
# Remote cluster controls our user database, including the
# admin flag.
- user.update_attributes!(is_admin: remote_user['is_admin'])
+ user.update!(is_admin: remote_user['is_admin'])
end
end
end
return nil
end
end
- auth.update_attributes!(user: user,
+ auth.update!(user: user,
api_token: stored_secret,
api_client_id: 0,
scopes: scopes,
super(permit_attribute_params(raw_params), *args)
end
- def update_attributes raw_params={}, *args
+ def update raw_params={}, *args
super(self.class.permit_attribute_params(raw_params), *args)
end
if self.state != Queued
raise LockFailedError.new("cannot lock when #{self.state}")
end
- self.update_attributes!(state: Locked)
+ self.update!(state: Locked)
end
end
if self.state != Locked
raise InvalidStateTransitionError.new("cannot unlock when #{self.state}")
end
- self.update_attributes!(state: Queued)
+ self.update!(state: Queued)
end
end
# ensure the token doesn't validate later in the same
# transaction (e.g., in a test case) by satisfying expires_at >
# transaction timestamp.
- self.auth.andand.update_attributes(expires_at: db_transaction_time)
+ self.auth.andand.update(expires_at: db_transaction_time)
self.auth = nil
return
elsif self.auth
# Queued with priority 0. (OTOH, if the child is already
# running, leave it alone so it can get cancelled the
# usual way, get a copy of the log collection, etc.)
- cr.update_attributes!(state: ContainerRequest::Final)
+ cr.update!(state: ContainerRequest::Final)
end
end
end
end
elsif state == Committed
# Behave as if the container is cancelled
- update_attributes!(state: Final)
+ update!(state: Final)
end
return true
end
end
end
end
- update_attributes!(state: Final)
+ update!(state: Final)
end
def update_collections(container:, collections: ['log', 'output'])
end
def set_priority_zero
- self.update_attributes!(priority: 0) if self.priority > 0 && self.state != Final
+ self.update!(priority: 0) if self.priority > 0 && self.state != Final
end
protected
end
def assert_finished
- update_attributes(finished_at: finished_at || db_current_time,
+ update(finished_at: finished_at || db_current_time,
success: success.nil? ? false : success,
running: false)
end
end
@bypass_arvados_authorization = true
- self.update_attributes!(o.select { |k,v|
+ self.update!(o.select { |k,v|
[:bytes_total,
:bytes_free,
:is_readable,
# as the new node. Clear the ip_address field on the stale
# nodes. Otherwise, we (via SLURM) might inadvertently connect
# to the new node using the old node's hostname.
- stale_node.update_attributes!(ip_address: nil)
+ stale_node.update!(ip_address: nil)
end
end
if hostname_before_last_save && saved_change_to_hostname?
end
if redirect_to_new_user
- update_attributes!(redirect_to_user_uuid: new_user.uuid, username: nil)
+ update!(redirect_to_user_uuid: new_user.uuid, username: nil)
end
skip_check_permissions_against_full_refresh do
update_permissions self.uuid, self.uuid, CAN_MANAGE_PERM
Metadatum.where('head like ?', 'orvos#%').each do |m|
kind_uuid = m.head.match /^(orvos\#.*)\#([-0-9a-z]+)$/
if kind_uuid
- m.update_attributes(head_kind: kind_uuid[1],
+ m.update(head_kind: kind_uuid[1],
head: kind_uuid[2])
end
end
def down
begin
Metadatum.where('head_kind is not null and head_kind <> ? and head is not null', '').each do |m|
- m.update_attributes(head: m.head_kind + '#' + m.head)
+ m.update(head: m.head_kind + '#' + m.head)
end
rescue
end
include CurrentApiClient
def up
act_as_system_user do
- anonymous_group.update_attributes group_class: 'role', name: 'Anonymous users', description: 'Anonymous users'
+ anonymous_group.update group_class: 'role', name: 'Anonymous users', description: 'Anonymous users'
end
end
def down
act_as_system_user do
- anonymous_group.update_attributes group_class: nil, name: 'Anonymous group', description: 'Anonymous group'
+ anonymous_group.update group_class: nil, name: 'Anonymous group', description: 'Anonymous group'
end
end
end
attributes[:properties]["migrated_from"] ||= coll.uuid
coll_copy = Collection.create!(attributes)
Log.log_create(coll_copy)
- coll.update_attributes(portable_data_hash: stripped_pdh)
+ coll.update(portable_data_hash: stripped_pdh)
Log.log_update(coll, start_log)
end
end
# This no-op update has the side effect that the update hooks
# will merge the highest available permission into this one
# and then delete the others.
- link.update_attributes!(properties: link.properties.dup)
+ link.update!(properties: link.properties.dup)
end
rows = ActiveRecord::Base.connection.select_all("SELECT MIN(uuid) AS uuid, COUNT(uuid) AS n FROM links
rows.each do |row|
Rails.logger.debug "DedupPermissionLinks: consolidating #{row['n']} links into #{row['uuid']}"
link = Link.find_by_uuid(row['uuid'])
- link.update_attributes!(properties: link.properties.dup)
+ link.update!(properties: link.properties.dup)
end
end
end
end
if (auth.user.uuid =~ /-tpzed-000000000000000/).nil? and (auth.user.uuid =~ /-tpzed-anonymouspublic/).nil?
CurrentApiClientHelper.act_as_system_user do
- auth.update_attributes!(expires_at: exp_date)
+ auth.update!(expires_at: exp_date)
end
token_count += 1
end
module TrashableController
def destroy
if !@object.is_trashed
- @object.update_attributes!(trash_at: db_current_time)
+ @object.update!(trash_at: db_current_time)
end
earliest_delete = (@object.trash_at +
Rails.configuration.Collections.BlobSigningTTL)
if @object.delete_at > earliest_delete
- @object.update_attributes!(delete_at: earliest_delete)
+ @object.update!(delete_at: earliest_delete)
end
show
end
def trash
if !@object.is_trashed
- @object.update_attributes!(trash_at: db_current_time)
+ @object.update!(trash_at: db_current_time)
end
show
end
test "update without deleting secret_mounts" do
authorize_with :active
req = container_requests(:uncommitted)
- req.update_attributes!(secret_mounts: {'/foo' => {'kind' => 'json', 'content' => 'bar'}})
+ req.update!(secret_mounts: {'/foo' => {'kind' => 'json', 'content' => 'bar'}})
patch :update, params: {
id: req.uuid,
test "filter on container subproperty runtime_status[foo] = bar" do
ctr = containers(:running)
act_as_system_user do
- ctr.update_attributes!(runtime_status: {foo: 'bar'})
+ ctr.update!(runtime_status: {foo: 'bar'})
end
authorize_with :active
get :index, params: {
innertrash = Collection.create!(name: 'inner-trashed', owner_uuid: innerproj.uuid, trash_at: trashtime)
innertrashproj = Group.create!(group_class: 'project', name: 'inner-trashed-proj', owner_uuid: innerproj.uuid, trash_at: trashtime)
outertrash = Collection.create!(name: 'outer-trashed', owner_uuid: outerproj.uuid, trash_at: trashtime)
- innerproj.update_attributes!(frozen_by_uuid: users(:active).uuid)
+ innerproj.update!(frozen_by_uuid: users(:active).uuid)
get :contents, params: {id: outerproj.uuid, include_trash: true, recursive: true}
assert_response :success
uuids = json_response['items'].collect { |item| item['uuid'] }
['dst', :project_viewer_trustedclient]].each do |which_scoped, auth|
test "refuse to merge with scoped #{which_scoped} token" do
act_as_system_user do
- api_client_authorizations(auth).update_attributes(scopes: ["GET /", "POST /", "PUT /"])
+ api_client_authorizations(auth).update(scopes: ["GET /", "POST /", "PUT /"])
end
authorize_with(:active_trustedclient)
post(:merge, params: {
assert group.valid?, "group is not valid"
# update 1
- group.update_attributes!(name: "test create and update name 1")
+ group.update!(name: "test create and update name 1")
results = Group.where(uuid: group.uuid)
assert_equal "test create and update name 1", results.first.name, "Expected name to be updated to 1"
updated_at_1 = results.first.updated_at.to_f
# update 2
- group.update_attributes!(name: "test create and update name 2")
+ group.update!(name: "test create and update name 2")
results = Group.where(uuid: group.uuid)
assert_equal "test create and update name 2", results.first.name, "Expected name to be updated to 2"
updated_at_2 = results.first.updated_at.to_f
c = Collection.create!(properties: {})
assert_equal({}, c.properties)
- c.update_attributes(properties: {'foo' => 'foo'})
+ c.update(properties: {'foo' => 'foo'})
c.reload
assert_equal({'foo' => 'foo'}, c.properties)
- c.update_attributes(properties: nil)
+ c.update(properties: nil)
c.reload
assert_equal({}, c.properties)
- c.update_attributes(properties: {foo: 'bar'})
+ c.update(properties: {foo: 'bar'})
assert_equal({'foo' => 'bar'}, c.properties)
c.reload
assert_equal({'foo' => 'bar'}, c.properties)
assert_equal 34, c.file_size_total
# Updating the manifest should change file stats
- c.update_attributes(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:34:foo.txt 0:34:foo2.txt\n")
+ c.update(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:34:foo.txt 0:34:foo2.txt\n")
assert c.valid?
assert_equal 2, c.file_count
assert_equal 68, c.file_size_total
# Updating file stats and the manifest should use manifest values
- c.update_attributes(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:34:foo.txt\n", file_count:10, file_size_total: 10)
+ c.update(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:34:foo.txt\n", file_count:10, file_size_total: 10)
assert c.valid?
assert_equal 1, c.file_count
assert_equal 34, c.file_size_total
# Updating just the file stats should be ignored
- c.update_attributes(file_count: 10, file_size_total: 10)
+ c.update(file_count: 10, file_size_total: 10)
assert c.valid?
assert_equal 1, c.file_count
assert_equal 34, c.file_size_total
assert_equal 1, c.version
assert_equal false, c.preserve_version
# Make a versionable update, it shouldn't create a new version yet
- c.update_attributes!({'name' => 'bar'})
+ c.update!({'name' => 'bar'})
c.reload
assert_equal 'bar', c.name
assert_equal 1, c.version
c.update_column('modified_at', fifteen_min_ago) # Update without validations/callbacks
c.reload
assert_equal fifteen_min_ago.to_i, c.modified_at.to_i
- c.update_attributes!({'name' => 'baz'})
+ c.update!({'name' => 'baz'})
c.reload
assert_equal 'baz', c.name
assert_equal 2, c.version
# Make another update, no new version should be created
- c.update_attributes!({'name' => 'foobar'})
+ c.update!({'name' => 'foobar'})
c.reload
assert_equal 'foobar', c.name
assert_equal 2, c.version
assert_not_nil c.replication_confirmed_at
assert_not_nil c.replication_confirmed
# Make the versionable update
- c.update_attributes!({'name' => 'foobarbaz'})
+ c.update!({'name' => 'foobarbaz'})
c.reload
assert_equal 'foobarbaz', c.name
assert_equal 3, c.version
assert_equal 1, c.version
assert_equal false, c.preserve_version
# This update shouldn't produce a new version, as the idle time is not up
- c.update_attributes!({
+ c.update!({
'name' => 'bar'
})
c.reload
assert_equal false, c.preserve_version
# This update should produce a new version, even if the idle time is not up
# and also keep the preserve_version=true flag to persist it.
- c.update_attributes!({
+ c.update!({
'name' => 'baz',
'preserve_version' => true
})
# Make sure preserve_version is not disabled after being enabled, unless
# a new version is created.
# This is a non-versionable update
- c.update_attributes!({
+ c.update!({
'preserve_version' => false,
'replication_desired' => 2
})
assert_equal 2, c.replication_desired
assert_equal true, c.preserve_version
# This is a versionable update
- c.update_attributes!({
+ c.update!({
'preserve_version' => false,
'name' => 'foobar'
})
assert_equal false, c.preserve_version
assert_equal 'foobar', c.name
# Flipping only 'preserve_version' to true doesn't create a new version
- c.update_attributes!({'preserve_version' => true})
+ c.update!({'preserve_version' => true})
c.reload
assert_equal 3, c.version
assert_equal true, c.preserve_version
assert c.valid?
assert_equal false, c.preserve_version
modified_at = c.modified_at.to_f
- c.update_attributes!({'preserve_version' => true})
+ c.update!({'preserve_version' => true})
c.reload
assert_equal true, c.preserve_version
assert_equal modified_at, c.modified_at.to_f,
assert_equal 1, c.version
assert_raises(ActiveRecord::RecordInvalid) do
- c.update_attributes!({
+ c.update!({
name => new_value
})
end
assert c.valid?
assert_equal 1, c.version
# Make changes so that a new version is created
- c.update_attributes!({'name' => 'bar'})
+ c.update!({'name' => 'bar'})
c.reload
assert_equal 2, c.version
assert_equal 2, Collection.where(current_version_uuid: c.uuid).count
new_uuid = 'zzzzz-4zz18-somefakeuuidnow'
assert_empty Collection.where(uuid: new_uuid)
# Update UUID on current version, check that both collections point to it
- c.update_attributes!({'uuid' => new_uuid})
+ c.update!({'uuid' => new_uuid})
c.reload
assert_equal new_uuid, c.uuid
assert_equal 2, Collection.where(current_version_uuid: new_uuid).count
# Set up initial collection
c = create_collection 'foo', Encoding::US_ASCII
assert c.valid?
- c.update_attributes!({'properties' => value_1})
+ c.update!({'properties' => value_1})
c.reload
assert c.changes.keys.empty?
c.properties = value_2
assert c.valid?
original_version_modified_at = c.modified_at.to_f
# Make changes so that a new version is created
- c.update_attributes!({'name' => 'bar'})
+ c.update!({'name' => 'bar'})
c.reload
assert_equal 2, c.version
# Get the old version
# Make update on current version so old version get the attribute synced;
# its modified_at should not change.
new_replication = 3
- c.update_attributes!({'replication_desired' => new_replication})
+ c.update!({'replication_desired' => new_replication})
c.reload
assert_equal new_replication, c.replication_desired
c_old.reload
c = create_collection 'foo', Encoding::US_ASCII
assert c.valid?
# Make changes so that a new version is created
- c.update_attributes!({'name' => 'bar'})
+ c.update!({'name' => 'bar'})
c.reload
assert_equal 2, c.version
# Get the old version
assert_not_equal first_val, c.attributes[attr]
# Make changes so that a new version is created and a synced field is
# updated on both
- c.update_attributes!({'name' => 'bar', attr => first_val})
+ c.update!({'name' => 'bar', attr => first_val})
c.reload
assert_equal 2, c.version
assert_equal first_val, c.attributes[attr]
assert_equal first_val, Collection.where(current_version_uuid: c.uuid, version: 1).first.attributes[attr]
# Only make an update on the same synced field & check that the previously
# created version also gets it.
- c.update_attributes!({attr => second_val})
+ c.update!({attr => second_val})
c.reload
assert_equal 2, c.version
assert_equal second_val, c.attributes[attr]
# Update attribute and check if version number should be incremented
old_value = c.attributes[attr]
- c.update_attributes!({attr => val})
+ c.update!({attr => val})
assert_equal new_version_expected, c.version == 2
assert_equal val, c.attributes[attr]
col2 = create_collection 'bar', Encoding::US_ASCII
assert col2.valid?
assert_equal 1, col2.version
- col2.update_attributes({name: 'baz'})
+ col2.update({name: 'baz'})
assert_equal 2, col2.version
# Try to make col2 a past version of col1. It shouldn't be possible
- col2.update_attributes({current_version_uuid: col1.uuid})
+ col2.update({current_version_uuid: col1.uuid})
assert col2.invalid?
col2.reload
assert_not_equal col1.uuid, col2.current_version_uuid
test "storage_classes_desired cannot be empty" do
act_as_user users(:active) do
c = collections(:collection_owned_by_active)
- c.update_attributes storage_classes_desired: ["hot"]
+ c.update storage_classes_desired: ["hot"]
assert_equal ["hot"], c.storage_classes_desired
assert_raise ArvadosModel::InvalidStateTransitionError do
- c.update_attributes storage_classes_desired: []
+ c.update storage_classes_desired: []
end
end
end
test "storage classes lists should only contain non-empty strings" do
c = collections(:storage_classes_desired_default_unconfirmed)
act_as_user users(:admin) do
- assert c.update_attributes(storage_classes_desired: ["default", "a_string"],
+ assert c.update(storage_classes_desired: ["default", "a_string"],
storage_classes_confirmed: ["another_string"])
[
["storage_classes_desired", ["default", 42]],
["storage_classes_confirmed", [""]],
].each do |attr, val|
assert_raise ArvadosModel::InvalidStateTransitionError do
- assert c.update_attributes({attr => val})
+ assert c.update({attr => val})
end
end
end
test "storage_classes_confirmed* can be set by admin user" do
c = collections(:storage_classes_desired_default_unconfirmed)
act_as_user users(:admin) do
- assert c.update_attributes(storage_classes_confirmed: ["default"],
+ assert c.update(storage_classes_confirmed: ["default"],
storage_classes_confirmed_at: Time.now)
end
end
c = collections(:storage_classes_desired_default_unconfirmed)
# Cannot set just one at a time.
assert_raise ArvadosModel::PermissionDeniedError do
- c.update_attributes storage_classes_confirmed: ["default"]
+ c.update storage_classes_confirmed: ["default"]
end
c.reload
assert_raise ArvadosModel::PermissionDeniedError do
- c.update_attributes storage_classes_confirmed_at: Time.now
+ c.update storage_classes_confirmed_at: Time.now
end
# Cannot set bot at once, either.
c.reload
assert_raise ArvadosModel::PermissionDeniedError do
- assert c.update_attributes(storage_classes_confirmed: ["default"],
+ assert c.update(storage_classes_confirmed: ["default"],
storage_classes_confirmed_at: Time.now)
end
end
c = collections(:storage_classes_desired_default_confirmed_default)
# Cannot clear just one at a time.
assert_raise ArvadosModel::PermissionDeniedError do
- c.update_attributes storage_classes_confirmed: []
+ c.update storage_classes_confirmed: []
end
c.reload
assert_raise ArvadosModel::PermissionDeniedError do
- c.update_attributes storage_classes_confirmed_at: nil
+ c.update storage_classes_confirmed_at: nil
end
# Can clear both at once.
c.reload
- assert c.update_attributes(storage_classes_confirmed: [],
+ assert c.update(storage_classes_confirmed: [],
storage_classes_confirmed_at: nil)
end
end
Rails.configuration.Collections.DefaultReplication = 2
act_as_user users(:active) do
c = collections(:replication_undesired_unconfirmed)
- c.update_attributes replication_desired: ask
+ c.update replication_desired: ask
assert_equal ask, c.replication_desired
end
end
test "replication_confirmed* can be set by admin user" do
c = collections(:replication_desired_2_unconfirmed)
act_as_user users(:admin) do
- assert c.update_attributes(replication_confirmed: 2,
+ assert c.update(replication_confirmed: 2,
replication_confirmed_at: Time.now)
end
end
c = collections(:replication_desired_2_unconfirmed)
# Cannot set just one at a time.
assert_raise ArvadosModel::PermissionDeniedError do
- c.update_attributes replication_confirmed: 1
+ c.update replication_confirmed: 1
end
assert_raise ArvadosModel::PermissionDeniedError do
- c.update_attributes replication_confirmed_at: Time.now
+ c.update replication_confirmed_at: Time.now
end
# Cannot set both at once, either.
assert_raise ArvadosModel::PermissionDeniedError do
- c.update_attributes(replication_confirmed: 1,
+ c.update(replication_confirmed: 1,
replication_confirmed_at: Time.now)
end
end
c = collections(:replication_desired_2_confirmed_2)
# Cannot clear just one at a time.
assert_raise ArvadosModel::PermissionDeniedError do
- c.update_attributes replication_confirmed: nil
+ c.update replication_confirmed: nil
end
c.reload
assert_raise ArvadosModel::PermissionDeniedError do
- c.update_attributes replication_confirmed_at: nil
+ c.update replication_confirmed_at: nil
end
# Can clear both at once.
c.reload
- assert c.update_attributes(replication_confirmed: nil,
+ assert c.update(replication_confirmed: nil,
replication_confirmed_at: nil)
end
end
test "clear replication_confirmed* when introducing a new block in manifest" do
c = collections(:replication_desired_2_confirmed_2)
act_as_user users(:active) do
- assert c.update_attributes(manifest_text: collections(:user_agreement).signed_manifest_text_only_for_tests)
+ assert c.update(manifest_text: collections(:user_agreement).signed_manifest_text_only_for_tests)
assert_nil c.replication_confirmed
assert_nil c.replication_confirmed_at
end
c = collections(:replication_desired_2_confirmed_2)
act_as_user users(:active) do
new_manifest = c.signed_manifest_text_only_for_tests.sub(':bar', ':foo')
- assert c.update_attributes(manifest_text: new_manifest)
+ assert c.update(manifest_text: new_manifest)
assert_equal 2, c.replication_confirmed
assert_not_nil c.replication_confirmed_at
end
# not, this test would pass without testing the relevant case):
assert_operator new_manifest.length+40, :<, c.signed_manifest_text_only_for_tests.length
- assert c.update_attributes(manifest_text: new_manifest)
+ assert c.update(manifest_text: new_manifest)
assert_equal 2, c.replication_confirmed
assert_not_nil c.replication_confirmed_at
end
act_as_user users(:active) do
t0 = db_current_time
c = Collection.create!(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:x\n", name: 'foo')
- c.update_attributes! trash_at: (t0 + 1.hours)
+ c.update! trash_at: (t0 + 1.hours)
c.reload
sig_exp = /\+A[0-9a-f]{40}\@([0-9]+)/.match(c.signed_manifest_text_only_for_tests)[1].to_i
assert_operator sig_exp.to_i, :<=, (t0 + 1.hours).to_i
assert_not_empty c, 'Should be able to find live collection'
# mark collection as expired
- c.first.update_attributes!(trash_at: Time.new.strftime("%Y-%m-%d"))
+ c.first.update!(trash_at: Time.new.strftime("%Y-%m-%d"))
c = Collection.readable_by(current_user).where(uuid: uuid)
assert_empty c, 'Should not be able to find expired collection'
act_as_user users(:active) do
t0 = db_current_time
c = Collection.create!(manifest_text: '', name: 'foo')
- c.update_attributes! trash_at: (t0 - 2.weeks)
+ c.update! trash_at: (t0 - 2.weeks)
c.reload
assert_operator c.trash_at, :>, t0
end
else
c = collections(fixture_name)
end
- updates_ok = c.update_attributes(updates)
+ updates_ok = c.update(updates)
expect_valid = expect[:state] != :invalid
assert_equal expect_valid, updates_ok, c.errors.full_messages.to_s
case expect[:state]
start = db_current_time
act_as_user users(:active) do
c = Collection.create!(manifest_text: '', name: 'foo')
- c.update_attributes!(trash_at: start + 86400.seconds)
+ c.update!(trash_at: start + 86400.seconds)
assert_operator c.delete_at, :>=, start + (86400*22).seconds
assert_operator c.delete_at, :<, start + (86400*22 + 30).seconds
c.destroy
c = Collection.create!(manifest_text: '', name: 'foo')
- c.update_attributes!(is_trashed: true)
+ c.update!(is_trashed: true)
assert_operator c.delete_at, :>=, start + (86400*21).seconds
end
end
def lock_and_run(ctr)
act_as_system_user do
- ctr.update_attributes!(state: Container::Locked)
- ctr.update_attributes!(state: Container::Running)
+ ctr.update!(state: Container::Locked)
+ ctr.update!(state: Container::Running)
end
end
cr.save!
assert_raises(ActiveRecord::RecordInvalid) do
cr = ContainerRequest.find_by_uuid cr.uuid
- cr.update_attributes!({state: "Committed",
+ cr.update!({state: "Committed",
priority: 1}.merge(value))
end
end
test "Update from fixture" do
set_user_from_auth :active
cr = ContainerRequest.find_by_uuid(container_requests(:running).uuid)
- cr.update_attributes!(description: "New description")
+ cr.update!(description: "New description")
assert_equal "New description", cr.description
end
cr = create_minimal_req!(state: "Uncommitted", priority: 1)
cr.save!
cr = ContainerRequest.find_by_uuid cr.uuid
- cr.update_attributes!(state: "Committed",
+ cr.update!(state: "Committed",
runtime_constraints: {"vcpus" => 1, "ram" => 23})
assert_not_nil cr.container_uuid
end
assert_operator c1.priority, :<, c2.priority
c2priority_was = c2.priority
- cr1.update_attributes!(priority: 0)
+ cr1.update!(priority: 0)
c1.reload
assert_equal 0, c1.priority
act_as_system_user do
Container.find_by_uuid(cr.container_uuid).
- update_attributes!(state: Container::Cancelled, cost: 1.25)
+ update!(state: Container::Cancelled, cost: 1.25)
end
cr.reload
c = act_as_system_user do
c = Container.find_by_uuid(cr.container_uuid)
- c.update_attributes!(state: Container::Locked)
- c.update_attributes!(state: Container::Running)
+ c.update!(state: Container::Locked)
+ c.update!(state: Container::Running)
c
end
output_pdh = '1f4b0bc7583c2a7f9102c395f4ffc5e3+45'
log_pdh = 'fa7aeb5140e2848d39b416daeef4ffc5+45'
act_as_system_user do
- c.update_attributes!(state: Container::Complete,
+ c.update!(state: Container::Complete,
cost: 1.25,
output: output_pdh,
log: log_pdh)
c = act_as_system_user do
c = Container.find_by_uuid(cr.container_uuid)
- c.update_attributes!(state: Container::Locked)
- c.update_attributes!(state: Container::Running,
+ c.update!(state: Container::Locked)
+ c.update!(state: Container::Running,
output: output_pdh,
log: log_pdh)
c
act_as_system_user do
Collection.where(portable_data_hash: output_pdh).delete_all
Collection.where(portable_data_hash: log_pdh).delete_all
- c.update_attributes!(state: Container::Complete)
+ c.update!(state: Container::Complete)
end
cr.reload
c = act_as_system_user do
c = Container.find_by_uuid(cr.container_uuid)
- c.update_attributes!(state: Container::Locked)
- c.update_attributes!(state: Container::Running)
+ c.update!(state: Container::Locked)
+ c.update!(state: Container::Running)
c
end
# increasing priority of the most recent toplevel container should
# reprioritize all of its descendants (including the shared
# grandchild) above everything else.
- toplevel_crs[2].update_attributes!(priority: 72)
+ toplevel_crs[2].update!(priority: 72)
(parents + children + grandchildren + [shared_grandchild]).map(&:reload)
assert_operator shared_grandchild.priority, :>, grandchildren[0].priority
assert_operator shared_grandchild.priority, :>, children[0].priority
# cancelling the most recent toplevel container should
# reprioritize all of its descendants (except the shared
# grandchild) to zero
- toplevel_crs[2].update_attributes!(priority: 0)
+ toplevel_crs[2].update!(priority: 0)
(parents + children + grandchildren + [shared_grandchild]).map(&:reload)
assert_operator 0, :==, parents[2].priority
assert_operator 0, :==, children[2].priority
# cancel a child request, the parent should be > 0 but
# the child and grandchild go to 0.
- children_crs[1].update_attributes!(priority: 0)
+ children_crs[1].update!(priority: 0)
(parents + children + grandchildren + [shared_grandchild]).map(&:reload)
assert_operator 0, :<, parents[1].priority
assert_operator parents[0].priority, :>, parents[1].priority
# update the parent, it should get a higher priority but the children and
# grandchildren should remain at 0
- toplevel_crs[1].update_attributes!(priority: 6)
+ toplevel_crs[1].update!(priority: 6)
(parents + children + grandchildren + [shared_grandchild]).map(&:reload)
assert_operator 0, :<, parents[1].priority
assert_operator parents[0].priority, :<, parents[1].priority
# should be assigned.
# * When use_existing is false, a different container should be assigned.
# * When env1 and env2 are different, a different container should be assigned.
- cr2.update_attributes!({state: ContainerRequest::Committed})
+ cr2.update!({state: ContainerRequest::Committed})
assert_equal (cr2.use_existing == true and (env1 == env2)),
(cr1.container_uuid == cr2.container_uuid)
end
c = act_as_system_user do
c = Container.find_by_uuid(cr.container_uuid)
- c.update_attributes!(state: Container::Locked)
- c.update_attributes!(state: Container::Running)
+ c.update!(state: Container::Locked)
+ c.update!(state: Container::Running)
c
end
prev_container_uuid = cr.container_uuid
act_as_system_user do
- c.update_attributes!(cost: 0.5, subrequests_cost: 1.25)
- c.update_attributes!(state: Container::Cancelled)
+ c.update!(cost: 0.5, subrequests_cost: 1.25)
+ c.update!(state: Container::Cancelled)
end
cr.reload
c = act_as_system_user do
c = Container.find_by_uuid(cr.container_uuid)
- c.update_attributes!(state: Container::Locked)
- c.update_attributes!(state: Container::Running)
- c.update_attributes!(cost: 0.125)
- c.update_attributes!(state: Container::Cancelled)
+ c.update!(state: Container::Locked)
+ c.update!(state: Container::Running)
+ c.update!(cost: 0.125)
+ c.update!(state: Container::Cancelled)
c
end
c = act_as_system_user do
c = Container.find_by_uuid(cr.container_uuid)
assert_equal spec.token, c.runtime_token
- c.update_attributes!(state: Container::Locked)
- c.update_attributes!(state: Container::Running)
+ c.update!(state: Container::Locked)
+ c.update!(state: Container::Running)
c
end
prev_container_uuid = cr.container_uuid
act_as_system_user do
- c.update_attributes!(state: Container::Cancelled)
+ c.update!(state: Container::Cancelled)
end
cr.reload
c = act_as_system_user do
c = Container.find_by_uuid(cr.container_uuid)
assert_equal spec.token, c.runtime_token
- c.update_attributes!(state: Container::Cancelled)
+ c.update!(state: Container::Cancelled)
c
end
c = act_as_system_user do
c = Container.find_by_uuid(cr.container_uuid)
- c.update_attributes!(state: Container::Locked)
- c.update_attributes!(state: Container::Running)
+ c.update!(state: Container::Locked)
+ c.update!(state: Container::Running)
c
end
logc = Collection.new(manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n")
logc.save!
c = Container.find_by_uuid(cr.container_uuid)
- c.update_attributes!(state: Container::Cancelled, log: logc.portable_data_hash)
+ c.update!(state: Container::Cancelled, log: logc.portable_data_hash)
c
end
end
cr1 = create_minimal_req!(priority: 1, state: "Committed", container_count_max: 2, command: ["echo", "foo1"])
c1 = Container.find_by_uuid(cr1.container_uuid)
act_as_system_user do
- c1.update_attributes!(state: Container::Locked)
- c1.update_attributes!(state: Container::Running)
+ c1.update!(state: Container::Locked)
+ c1.update!(state: Container::Running)
end
cr2 = with_container_auth(c1) do
end
c2 = Container.find_by_uuid(cr2.container_uuid)
act_as_system_user do
- c2.update_attributes!(state: Container::Locked)
- c2.update_attributes!(state: Container::Running)
+ c2.update!(state: Container::Locked)
+ c2.update!(state: Container::Running)
end
cr3 = with_container_auth(c2) do
c3 = Container.find_by_uuid(cr3.container_uuid)
act_as_system_user do
- c3.update_attributes!(state: Container::Locked)
- c3.update_attributes!(state: Container::Running)
+ c3.update!(state: Container::Locked)
+ c3.update!(state: Container::Running)
end
# All the containers are in running state
cr1 = create_minimal_req!(priority: 1, state: "Committed", container_count_max: 2, command: ["echo", "foo1"])
c1 = Container.find_by_uuid(cr1.container_uuid)
act_as_system_user do
- c1.update_attributes!(state: Container::Locked)
- c1.update_attributes!(state: Container::Running)
+ c1.update!(state: Container::Locked)
+ c1.update!(state: Container::Running)
end
cr2 = with_container_auth(c1) do
end
c2 = Container.find_by_uuid(cr2.container_uuid)
act_as_system_user do
- c2.update_attributes!(state: Container::Locked)
- c2.update_attributes!(state: Container::Running)
+ c2.update!(state: Container::Locked)
+ c2.update!(state: Container::Running)
end
cr3 = with_container_auth(c2) do
c3 = Container.find_by_uuid(cr3.container_uuid)
act_as_system_user do
- c3.update_attributes!(state: Container::Locked)
- c3.update_attributes!(state: Container::Running)
+ c3.update!(state: Container::Locked)
+ c3.update!(state: Container::Running)
end
# All the containers are in running state
cr1 = create_minimal_req!(priority: 1, state: "Committed", container_count_max: 2, command: ["echo", "foo1"])
c1 = Container.find_by_uuid(cr1.container_uuid)
act_as_system_user do
- c1.update_attributes!(state: Container::Locked)
- c1.update_attributes!(state: Container::Running)
+ c1.update!(state: Container::Locked)
+ c1.update!(state: Container::Running)
end
cr2 = with_container_auth(c1) do
end
c2 = Container.find_by_uuid(cr2.container_uuid)
act_as_system_user do
- c2.update_attributes!(state: Container::Locked)
- c2.update_attributes!(state: Container::Running)
+ c2.update!(state: Container::Locked)
+ c2.update!(state: Container::Running)
end
cr3 = with_container_auth(c2) do
c3 = Container.find_by_uuid(cr3.container_uuid)
act_as_system_user do
- c3.update_attributes!(state: Container::Locked)
- c3.update_attributes!(state: Container::Running)
+ c3.update!(state: Container::Locked)
+ c3.update!(state: Container::Running)
end
# All the containers are in running state
logc.save!
c = Container.find_by_uuid(cr.container_uuid)
- c.update_attributes!(state: Container::Locked)
- c.update_attributes!(state: Container::Running)
- c.update_attributes!(state: final_state,
+ c.update!(state: Container::Locked)
+ c.update!(state: Container::Running)
+ c.update!(state: final_state,
exit_code: exit_code,
output: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45',
log: logc.portable_data_hash)
cr3 = create_minimal_req!(priority: 1, state: ContainerRequest::Uncommitted)
assert_equal ContainerRequest::Uncommitted, cr3.state
- cr3.update_attributes!(state: ContainerRequest::Committed)
+ cr3.update!(state: ContainerRequest::Committed)
assert_equal cr.container_uuid, cr3.container_uuid
assert_equal ContainerRequest::Final, cr3.state
end
# Even though preemptible is not allowed, we should be able to
# commit a CR that was created earlier when preemptible was the
# default.
- commit_later.update_attributes!(priority: 1, state: "Committed")
+ commit_later.update!(priority: 1, state: "Committed")
expect[false].push commit_later
end
# Cancelling the parent used to fail while updating the child
# containers' priority, because the child containers' unchanged
# preemptible fields caused validation to fail.
- parent.update_attributes!(state: 'Cancelled')
+ parent.update!(state: 'Cancelled')
[false, true].each do |pflag|
expect[pflag].each do |cr|
when 'Final'
act_as_system_user do
Container.find_by_uuid(cr.container_uuid).
- update_attributes!(state: Container::Cancelled)
+ update!(state: Container::Cancelled)
end
cr.reload
else
end
assert_equal state, cr.state
if permitted
- assert cr.update_attributes!(updates)
+ assert cr.update!(updates)
else
assert_raises(ActiveRecord::RecordInvalid) do
- cr.update_attributes!(updates)
+ cr.update!(updates)
end
end
end
assert_equal 1, c.priority
prj = Group.find_by_uuid cr.owner_uuid
- prj.update_attributes!(trash_at: db_current_time)
+ prj.update!(trash_at: db_current_time)
# the cr's container now has priority of 0
c.reload
# container request to go to final state and run the finalize
# function
act_as_system_user do
- c.update_attributes!(state: 'Cancelled', log: 'fa7aeb5140e2848d39b416daeef4ffc5+45')
+ c.update!(state: 'Cancelled', log: 'fa7aeb5140e2848d39b416daeef4ffc5+45')
end
c.reload
cr.reload
sm = {'/secret/foo' => {'kind' => 'text', 'content' => secret_string}}
set_user_from_auth :active
cr = create_minimal_req!
- assert_equal false, cr.update_attributes(state: "Committed",
+ assert_equal false, cr.update(state: "Committed",
priority: 1,
mounts: cr.mounts.merge(sm),
secret_mounts: sm)
assert_not_nil ApiClientAuthorization.find_by_uuid(spec.uuid)
act_as_system_user do
- c.update_attributes!(state: Container::Complete,
+ c.update!(state: Container::Complete,
exit_code: 0,
output: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45',
log: 'fa7aeb5140e2848d39b416daeef4ffc5+45')
assert_nil cr2.container_uuid
# Update cr2 to commited state, check for reuse, then run it
- cr2.update_attributes!({state: ContainerRequest::Committed})
+ cr2.update!({state: ContainerRequest::Committed})
assert_equal cr1.container_uuid, cr2.container_uuid
cr2.reload
logc.save!
c = Container.find_by_uuid(cr.container_uuid)
- c.update_attributes!(state: Container::Locked)
- c.update_attributes!(state: Container::Running)
+ c.update!(state: Container::Locked)
+ c.update!(state: Container::Running)
- c.update_attributes!(output_properties: container_prop)
+ c.update!(output_properties: container_prop)
- c.update_attributes!(state: Container::Complete,
+ c.update!(state: Container::Complete,
exit_code: 0,
output: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45',
log: logc.portable_data_hash)
cr = create_minimal_req!(priority: 5, state: "Committed", container_count_max: 3)
c = Container.find_by_uuid cr.container_uuid
act_as_system_user do
- c.update_attributes!(state: Container::Locked)
- c.update_attributes!(state: Container::Running)
- c.update_attributes!(state: Container::Cancelled, cost: 3)
+ c.update!(state: Container::Locked)
+ c.update!(state: Container::Running)
+ c.update!(state: Container::Cancelled, cost: 3)
end
cr.reload
assert_equal 3, cr.cumulative_cost
assert_equal c.uuid, cr2.requesting_container_uuid
c2 = Container.find_by_uuid cr2.container_uuid
act_as_system_user do
- c2.update_attributes!(state: Container::Locked)
- c2.update_attributes!(state: Container::Running)
+ c2.update!(state: Container::Locked)
+ c2.update!(state: Container::Running)
logc = Collection.new(owner_uuid: system_user_uuid,
manifest_text: ". ef772b2f28e2c8ca84de45466ed19ee9+7815 0:0:arv-mount.txt\n")
logc.save!
- c2.update_attributes!(state: Container::Complete,
+ c2.update!(state: Container::Complete,
exit_code: 0,
output: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45',
log: logc.portable_data_hash,
assert_equal 7, c.subrequests_cost
act_as_system_user do
- c.update_attributes!(state: Container::Complete, exit_code: 0, cost: 9)
+ c.update!(state: Container::Complete, exit_code: 0, cost: 9)
end
c.reload
def check_illegal_updates c, bad_updates
bad_updates.each do |u|
- refute c.update_attributes(u), u.inspect
+ refute c.update(u), u.inspect
refute c.valid?, u.inspect
c.reload
end
assert_equal Container::Queued, c.state
set_user_from_auth :dispatch1
- c.update_attributes! state: Container::Locked
- c.update_attributes! state: Container::Running
+ c.update! state: Container::Locked
+ c.update! state: Container::Running
[
'error', 'errorDetail', 'warning', 'warningDetail', 'activity'
].each do |k|
# String type is allowed
string_val = 'A string is accepted'
- c.update_attributes! runtime_status: {k => string_val}
+ c.update! runtime_status: {k => string_val}
assert_equal string_val, c.runtime_status[k]
# Other types aren't allowed
42, false, [], {}, nil
].each do |unallowed_val|
assert_raises ActiveRecord::RecordInvalid do
- c.update_attributes! runtime_status: {k => unallowed_val}
+ c.update! runtime_status: {k => unallowed_val}
end
end
end
assert_equal Container::Queued, c1.state
assert_raises ArvadosModel::PermissionDeniedError do
- c1.update_attributes! runtime_status: {'error' => 'Oops!'}
+ c1.update! runtime_status: {'error' => 'Oops!'}
end
set_user_from_auth :dispatch1
# Allow updates when state = Locked
- c1.update_attributes! state: Container::Locked
- c1.update_attributes! runtime_status: {'error' => 'Oops!'}
+ c1.update! state: Container::Locked
+ c1.update! runtime_status: {'error' => 'Oops!'}
assert c1.runtime_status.key? 'error'
# Reset when transitioning from Locked to Queued
- c1.update_attributes! state: Container::Queued
+ c1.update! state: Container::Queued
assert_equal c1.runtime_status, {}
# Allow updates when state = Running
- c1.update_attributes! state: Container::Locked
- c1.update_attributes! state: Container::Running
- c1.update_attributes! runtime_status: {'error' => 'Oops!'}
+ c1.update! state: Container::Locked
+ c1.update! state: Container::Running
+ c1.update! runtime_status: {'error' => 'Oops!'}
assert c1.runtime_status.key? 'error'
# Don't allow updates on other states
- c1.update_attributes! state: Container::Complete
+ c1.update! state: Container::Complete
assert_raises ActiveRecord::RecordInvalid do
- c1.update_attributes! runtime_status: {'error' => 'Some other error'}
+ c1.update! runtime_status: {'error' => 'Some other error'}
end
set_user_from_auth :active
c2, _ = minimal_new(attrs)
assert_equal c2.runtime_status, {}
set_user_from_auth :dispatch1
- c2.update_attributes! state: Container::Locked
- c2.update_attributes! state: Container::Running
- c2.update_attributes! state: Container::Cancelled
+ c2.update! state: Container::Locked
+ c2.update! state: Container::Running
+ c2.update! state: Container::Cancelled
assert_raises ActiveRecord::RecordInvalid do
- c2.update_attributes! runtime_status: {'error' => 'Oops!'}
+ c2.update! runtime_status: {'error' => 'Oops!'}
end
end
assert_not_equal c_older.uuid, c_recent.uuid
set_user_from_auth :dispatch1
- c_older.update_attributes!({state: Container::Locked})
- c_older.update_attributes!({state: Container::Running})
- c_older.update_attributes!(completed_attrs)
+ c_older.update!({state: Container::Locked})
+ c_older.update!({state: Container::Running})
+ c_older.update!(completed_attrs)
- c_recent.update_attributes!({state: Container::Locked})
- c_recent.update_attributes!({state: Container::Running})
- c_recent.update_attributes!(completed_attrs)
+ c_recent.update!({state: Container::Locked})
+ c_recent.update!({state: Container::Running})
+ c_recent.update!(completed_attrs)
reused = Container.find_reusable(common_attrs)
assert_not_nil reused
out1 = '1f4b0bc7583c2a7f9102c395f4ffc5e3+45'
log1 = collections(:real_log_collection).portable_data_hash
- c_output1.update_attributes!({state: Container::Locked})
- c_output1.update_attributes!({state: Container::Running})
- c_output1.update_attributes!(completed_attrs.merge({log: log1, output: out1}))
+ c_output1.update!({state: Container::Locked})
+ c_output1.update!({state: Container::Running})
+ c_output1.update!(completed_attrs.merge({log: log1, output: out1}))
out2 = 'fa7aeb5140e2848d39b416daeef4ffc5+45'
- c_output2.update_attributes!({state: Container::Locked})
- c_output2.update_attributes!({state: Container::Running})
- c_output2.update_attributes!(completed_attrs.merge({log: log1, output: out2}))
+ c_output2.update!({state: Container::Locked})
+ c_output2.update!({state: Container::Running})
+ c_output2.update!(completed_attrs.merge({log: log1, output: out2}))
set_user_from_auth :active
reused = Container.resolve(ContainerRequest.new(request_only(common_attrs)))
# Confirm the 3 container UUIDs are different.
assert_equal 3, [c_slower.uuid, c_faster_started_first.uuid, c_faster_started_second.uuid].uniq.length
set_user_from_auth :dispatch1
- c_slower.update_attributes!({state: Container::Locked})
- c_slower.update_attributes!({state: Container::Running,
+ c_slower.update!({state: Container::Locked})
+ c_slower.update!({state: Container::Running,
progress: 0.1})
- c_faster_started_first.update_attributes!({state: Container::Locked})
- c_faster_started_first.update_attributes!({state: Container::Running,
+ c_faster_started_first.update!({state: Container::Locked})
+ c_faster_started_first.update!({state: Container::Running,
progress: 0.15})
- c_faster_started_second.update_attributes!({state: Container::Locked})
- c_faster_started_second.update_attributes!({state: Container::Running,
+ c_faster_started_second.update!({state: Container::Locked})
+ c_faster_started_second.update!({state: Container::Running,
progress: 0.15})
reused = Container.find_reusable(common_attrs)
assert_not_nil reused
# Confirm the 3 container UUIDs are different.
assert_equal 3, [c_slower.uuid, c_faster_started_first.uuid, c_faster_started_second.uuid].uniq.length
set_user_from_auth :dispatch1
- c_slower.update_attributes!({state: Container::Locked})
- c_slower.update_attributes!({state: Container::Running,
+ c_slower.update!({state: Container::Locked})
+ c_slower.update!({state: Container::Running,
progress: 0.1})
- c_faster_started_first.update_attributes!({state: Container::Locked})
- c_faster_started_first.update_attributes!({state: Container::Running,
+ c_faster_started_first.update!({state: Container::Locked})
+ c_faster_started_first.update!({state: Container::Running,
progress: 0.15})
- c_faster_started_second.update_attributes!({state: Container::Locked})
- c_faster_started_second.update_attributes!({state: Container::Running,
+ c_faster_started_second.update!({state: Container::Locked})
+ c_faster_started_second.update!({state: Container::Running,
progress: 0.2})
reused = Container.find_reusable(common_attrs)
assert_not_nil reused
# Confirm the 3 container UUIDs are different.
assert_equal 3, [c_slower.uuid, c_faster_started_first.uuid, c_faster_started_second.uuid].uniq.length
set_user_from_auth :dispatch1
- c_slower.update_attributes!({state: Container::Locked})
- c_slower.update_attributes!({state: Container::Running,
+ c_slower.update!({state: Container::Locked})
+ c_slower.update!({state: Container::Running,
progress: 0.1})
- c_faster_started_first.update_attributes!({state: Container::Locked})
- c_faster_started_first.update_attributes!({state: Container::Running,
+ c_faster_started_first.update!({state: Container::Locked})
+ c_faster_started_first.update!({state: Container::Running,
runtime_status: {'warning' => 'This is not an error'},
progress: 0.15})
- c_faster_started_second.update_attributes!({state: Container::Locked})
+ c_faster_started_second.update!({state: Container::Locked})
assert_equal 0, Container.where("runtime_status->'error' is not null").count
- c_faster_started_second.update_attributes!({state: Container::Running,
+ c_faster_started_second.update!({state: Container::Running,
runtime_status: {'error' => 'Something bad happened'},
progress: 0.2})
assert_equal 1, Container.where("runtime_status->'error' is not null").count
# Confirm the 3 container UUIDs are different.
assert_equal 3, [c_low_priority.uuid, c_high_priority_older.uuid, c_high_priority_newer.uuid].uniq.length
set_user_from_auth :dispatch1
- c_low_priority.update_attributes!({state: Container::Locked,
+ c_low_priority.update!({state: Container::Locked,
priority: 1})
- c_high_priority_older.update_attributes!({state: Container::Locked,
+ c_high_priority_older.update!({state: Container::Locked,
priority: 2})
- c_high_priority_newer.update_attributes!({state: Container::Locked,
+ c_high_priority_newer.update!({state: Container::Locked,
priority: 2})
reused = Container.find_reusable(common_attrs)
assert_not_nil reused
c_running, _ = minimal_new(common_attrs.merge({use_existing: false}))
assert_not_equal c_failed.uuid, c_running.uuid
set_user_from_auth :dispatch1
- c_failed.update_attributes!({state: Container::Locked})
- c_failed.update_attributes!({state: Container::Running})
- c_failed.update_attributes!({state: Container::Complete,
+ c_failed.update!({state: Container::Locked})
+ c_failed.update!({state: Container::Running})
+ c_failed.update!({state: Container::Complete,
exit_code: 42,
log: 'ea10d51bcf88862dbcc36eb292017dfd+45',
output: 'ea10d51bcf88862dbcc36eb292017dfd+45'})
- c_running.update_attributes!({state: Container::Locked})
- c_running.update_attributes!({state: Container::Running,
+ c_running.update!({state: Container::Locked})
+ c_running.update!({state: Container::Running,
progress: 0.15})
reused = Container.find_reusable(common_attrs)
assert_not_nil reused
c_running, _ = minimal_new(common_attrs.merge({use_existing: false}))
assert_not_equal c_completed.uuid, c_running.uuid
set_user_from_auth :dispatch1
- c_completed.update_attributes!({state: Container::Locked})
- c_completed.update_attributes!({state: Container::Running})
- c_completed.update_attributes!({state: Container::Complete,
+ c_completed.update!({state: Container::Locked})
+ c_completed.update!({state: Container::Running})
+ c_completed.update!({state: Container::Complete,
exit_code: 0,
log: 'ea10d51bcf88862dbcc36eb292017dfd+45',
output: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45'})
- c_running.update_attributes!({state: Container::Locked})
- c_running.update_attributes!({state: Container::Running,
+ c_running.update!({state: Container::Locked})
+ c_running.update!({state: Container::Running,
progress: 0.15})
reused = Container.find_reusable(common_attrs)
assert_not_nil reused
c_running, _ = minimal_new(common_attrs.merge({use_existing: false}))
assert_not_equal c_running.uuid, c_locked.uuid
set_user_from_auth :dispatch1
- c_locked.update_attributes!({state: Container::Locked})
- c_running.update_attributes!({state: Container::Locked})
- c_running.update_attributes!({state: Container::Running,
+ c_locked.update!({state: Container::Locked})
+ c_running.update!({state: Container::Locked})
+ c_running.update!({state: Container::Running,
progress: 0.15})
reused = Container.find_reusable(common_attrs)
assert_not_nil reused
c_queued, _ = minimal_new(common_attrs.merge({use_existing: false}))
assert_not_equal c_queued.uuid, c_locked.uuid
set_user_from_auth :dispatch1
- c_locked.update_attributes!({state: Container::Locked})
+ c_locked.update!({state: Container::Locked})
reused = Container.find_reusable(common_attrs)
assert_not_nil reused
assert_equal reused.uuid, c_locked.uuid
attrs = REUSABLE_COMMON_ATTRS.merge({environment: {"var" => "failed"}})
c, _ = minimal_new(attrs)
set_user_from_auth :dispatch1
- c.update_attributes!({state: Container::Locked})
- c.update_attributes!({state: Container::Running})
- c.update_attributes!({state: Container::Complete,
+ c.update!({state: Container::Locked})
+ c.update!({state: Container::Running})
+ c.update!({state: Container::Complete,
exit_code: 33})
reused = Container.find_reusable(attrs)
assert_nil reused
c1_attrs = REUSABLE_COMMON_ATTRS.merge({environment: {"test" => name, "state" => c1_state}, scheduling_parameters: {"preemptible" => c1_preemptible}})
c1, _ = minimal_new(c1_attrs)
set_user_from_auth :dispatch1
- c1.update_attributes!({state: Container::Locked}) if c1_state != Container::Queued
- c1.update_attributes!({state: Container::Running, priority: c1_priority}) if c1_state == Container::Running
+ c1.update!({state: Container::Locked}) if c1_state != Container::Queued
+ c1.update!({state: Container::Running, priority: c1_priority}) if c1_state == Container::Running
c2_attrs = c1_attrs.merge({scheduling_parameters: {"preemptible" => c2_preemptible}})
reused = Container.find_reusable(c2_attrs)
if should_reuse && c1_priority > 0
{state: Container::Complete}]
c.lock
- c.update_attributes! state: Container::Running
+ c.update! state: Container::Running
check_illegal_modify c
check_bogus_states c
check_illegal_updates c, [{state: Container::Queued}]
c.reload
- c.update_attributes! priority: 3
+ c.update! priority: 3
end
test "Lock and unlock" do
c.lock
end
c.reload
- assert cr.update_attributes priority: 1
+ assert cr.update priority: 1
- refute c.update_attributes(state: Container::Running), "not locked"
+ refute c.update(state: Container::Running), "not locked"
c.reload
- refute c.update_attributes(state: Container::Complete), "not locked"
+ refute c.update(state: Container::Complete), "not locked"
c.reload
assert c.lock, show_errors(c)
refute c.locked_by_uuid
refute c.auth_uuid
- refute c.update_attributes(state: Container::Running), "not locked"
+ refute c.update(state: Container::Running), "not locked"
c.reload
refute c.locked_by_uuid
refute c.auth_uuid
assert c.lock, show_errors(c)
- assert c.update_attributes(state: Container::Running), show_errors(c)
+ assert c.update(state: Container::Running), show_errors(c)
assert c.locked_by_uuid
assert c.auth_uuid
end
c.reload
- assert c.update_attributes(state: Container::Complete), show_errors(c)
+ assert c.update(state: Container::Complete), show_errors(c)
refute c.locked_by_uuid
refute c.auth_uuid
set_user_from_auth :active
c, cr = minimal_new({container_count_max: 1})
set_user_from_auth :dispatch1
- assert c.update_attributes(state: Container::Cancelled), show_errors(c)
+ assert c.update(state: Container::Cancelled), show_errors(c)
check_no_change_from_cancelled c
cr.reload
assert_equal ContainerRequest::Final, cr.state
c, _ = minimal_new
set_user_from_auth :dispatch1
assert c.lock, show_errors(c)
- assert c.update_attributes(state: Container::Cancelled), show_errors(c)
+ assert c.update(state: Container::Cancelled), show_errors(c)
check_no_change_from_cancelled c
end
c, _ = minimal_new
set_user_from_auth :dispatch1
assert c.lock, show_errors(c)
- assert c.update_attributes(
+ assert c.update(
state: Container::Cancelled,
log: collections(:real_log_collection).portable_data_hash,
), show_errors(c)
c, _ = minimal_new
set_user_from_auth :dispatch1
c.lock
- c.update_attributes! state: Container::Running
- c.update_attributes! state: Container::Cancelled
+ c.update! state: Container::Running
+ c.update! state: Container::Cancelled
check_no_change_from_cancelled c
end
set_user_from_auth :dispatch1
c.lock
if start_state != Container::Locked
- c.update_attributes! state: Container::Running
+ c.update! state: Container::Running
if start_state != Container::Running
- c.update_attributes! state: start_state
+ c.update! state: start_state
end
end
end
assert_equal c.state, start_state
set_user_from_auth :active
assert_raises(ArvadosModel::PermissionDeniedError) do
- c.update_attributes! updates
+ c.update! updates
end
end
end
set_user_from_auth :dispatch1
c.lock
check_illegal_updates c, [{exit_code: 1}]
- c.update_attributes! state: Container::Running
- assert c.update_attributes(exit_code: 1)
- assert c.update_attributes(exit_code: 1, state: Container::Complete)
+ c.update! state: Container::Running
+ assert c.update(exit_code: 1)
+ assert c.update(exit_code: 1, state: Container::Complete)
end
test "locked_by_uuid can update log when locked/running, and output when running" do
set_user_from_auth :dispatch1
c.lock
assert_equal c.locked_by_uuid, Thread.current[:api_client_authorization].uuid
- c.update_attributes!(log: logpdh_time1)
- c.update_attributes!(state: Container::Running)
+ c.update!(log: logpdh_time1)
+ c.update!(state: Container::Running)
cr1.reload
cr2.reload
cr1log_uuid = cr1.log_uuid
assert_not_equal logcoll.uuid, cr2log_uuid
assert_not_equal cr1log_uuid, cr2log_uuid
- logcoll.update_attributes!(manifest_text: logcoll.manifest_text + ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo.txt\n")
+ logcoll.update!(manifest_text: logcoll.manifest_text + ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo.txt\n")
logpdh_time2 = logcoll.portable_data_hash
- assert c.update_attributes(output: collections(:collection_owned_by_active).portable_data_hash)
- assert c.update_attributes(log: logpdh_time2)
- assert c.update_attributes(state: Container::Complete, log: logcoll.portable_data_hash)
+ assert c.update(output: collections(:collection_owned_by_active).portable_data_hash)
+ assert c.update(log: logpdh_time2)
+ assert c.update(state: Container::Complete, log: logcoll.portable_data_hash)
c.reload
assert_equal collections(:collection_owned_by_active).portable_data_hash, c.output
assert_equal logpdh_time2, c.log
- refute c.update_attributes(output: nil)
- refute c.update_attributes(log: nil)
+ refute c.update(output: nil)
+ refute c.update(log: nil)
cr1.reload
cr2.reload
assert_equal cr1log_uuid, cr1.log_uuid
end
set_user_from_auth :dispatch1
c.lock
- c.update_attributes! state: Container::Running
+ c.update! state: Container::Running
if tok == "runtime_token"
auth = ApiClientAuthorization.validate(token: c.runtime_token)
Thread.current[:user] = auth.user
end
- assert c.update_attributes(gateway_address: "127.0.0.1:9")
- assert c.update_attributes(output: collections(:collection_owned_by_active).portable_data_hash)
- assert c.update_attributes(runtime_status: {'warning' => 'something happened'})
- assert c.update_attributes(progress: 0.5)
- assert c.update_attributes(exit_code: 0)
- refute c.update_attributes(log: collections(:real_log_collection).portable_data_hash)
+ assert c.update(gateway_address: "127.0.0.1:9")
+ assert c.update(output: collections(:collection_owned_by_active).portable_data_hash)
+ assert c.update(runtime_status: {'warning' => 'something happened'})
+ assert c.update(progress: 0.5)
+ assert c.update(exit_code: 0)
+ refute c.update(log: collections(:real_log_collection).portable_data_hash)
c.reload
- assert c.update_attributes(state: Container::Complete, exit_code: 0)
+ assert c.update(state: Container::Complete, exit_code: 0)
end
end
c, _ = minimal_new
set_user_from_auth :dispatch1
c.lock
- c.update_attributes! state: Container::Running
+ c.update! state: Container::Running
Thread.current[:api_client_authorization] = ApiClientAuthorization.find_by_uuid(c.auth_uuid)
Thread.current[:user] = User.find_by_id(Thread.current[:api_client_authorization].user_id)
assert_raises ActiveRecord::RecordInvalid do
- c.update_attributes! output: collections(:collection_not_readable_by_active).portable_data_hash
+ c.update! output: collections(:collection_not_readable_by_active).portable_data_hash
end
end
c, _ = minimal_new
set_user_from_auth :dispatch1
c.lock
- c.update_attributes! state: Container::Running
+ c.update! state: Container::Running
set_user_from_auth :running_to_be_deleted_container_auth
assert_raises(ArvadosModel::PermissionDeniedError) do
- c.update_attributes(output: collections(:foo_file).portable_data_hash)
+ c.update(output: collections(:foo_file).portable_data_hash)
end
end
c, _ = minimal_new
set_user_from_auth :dispatch1
c.lock
- c.update_attributes! state: Container::Running
+ c.update! state: Container::Running
output = Collection.find_by_uuid('zzzzz-4zz18-mto52zx1s7sn3jk')
assert output.is_trashed
- assert c.update_attributes output: output.portable_data_hash
- assert c.update_attributes! state: Container::Complete
+ assert c.update output: output.portable_data_hash
+ assert c.update! state: Container::Complete
end
test "not allowed to set trashed output that is not readable by current user" do
c, _ = minimal_new
set_user_from_auth :dispatch1
c.lock
- c.update_attributes! state: Container::Running
+ c.update! state: Container::Running
output = Collection.find_by_uuid('zzzzz-4zz18-mto52zx1s7sn3jr')
Thread.current[:user] = User.find_by_id(Thread.current[:api_client_authorization].user_id)
assert_raises ActiveRecord::RecordInvalid do
- c.update_attributes! output: output.portable_data_hash
+ c.update! output: output.portable_data_hash
end
end
container_count_max: 1, runtime_token: api_client_authorizations(:active).token)
set_user_from_auth :dispatch1
c.lock
- c.update_attributes!(state: Container::Running)
+ c.update!(state: Container::Running)
c.reload
assert c.secret_mounts.has_key?('/secret')
assert_equal api_client_authorizations(:active).token, c.runtime_token
- c.update_attributes!(final_attrs)
+ c.update!(final_attrs)
c.reload
assert_equal({}, c.secret_mounts)
assert_nil c.runtime_token
assert_equal(1, containers.length)
_, container1 = containers.shift
container1.lock
- container1.update_attributes!(state: Container::Cancelled)
+ container1.update!(state: Container::Cancelled)
container1.reload
request1 = requests.shift
request1.reload
end
container, request = minimal_new(request_params)
container.lock
- container.update_attributes!(state: Container::Running)
- container.update_attributes!(final_attrs)
+ container.update!(state: Container::Running)
+ container.update!(final_attrs)
return container, request
end
apiClientAuth = ApiClientAuthorization.where(api_token: 'atesttoken').first
refute_nil apiClientAuth
Thread.current[:user] = users(:admin)
- apiClientAuth.update_attributes expires_at: '2000-10-10'
+ apiClientAuth.update expires_at: '2000-10-10'
token2 = create_superuser_token
assert_not_nil token2
set_user_from_auth :active_trustedclient
g = Group.create!(name: "foo", group_class: "role")
assert_raises(ActiveRecord::RecordInvalid) do
- g.update_attributes!(group_class: "project")
+ g.update!(group_class: "project")
end
end
c = Collection.create!(name: "bzzz124")
assert_raises(ArvadosModel::PermissionDeniedError) do
- c.update_attributes!(owner_uuid: role.uuid)
+ c.update!(owner_uuid: role.uuid)
end
end
# Cannot set frozen_by_uuid to a different user
assert_raises do
- proj.update_attributes!(frozen_by_uuid: users(:spectator).uuid)
+ proj.update!(frozen_by_uuid: users(:spectator).uuid)
end
proj.reload
# First confirm we have write permission
assert Collection.create(name: 'bar', owner_uuid: proj.uuid)
assert_raises(ArvadosModel::PermissionDeniedError) do
- proj.update_attributes!(frozen_by_uuid: users(:spectator).uuid)
+ proj.update!(frozen_by_uuid: users(:spectator).uuid)
end
end
proj.reload
# Cannot set frozen_by_uuid without description (if so configured)
Rails.configuration.API.FreezeProjectRequiresDescription = true
err = assert_raises do
- proj.update_attributes!(frozen_by_uuid: users(:active).uuid)
+ proj.update!(frozen_by_uuid: users(:active).uuid)
end
assert_match /can only be set if description is non-empty/, err.inspect
proj.reload
err = assert_raises do
- proj.update_attributes!(frozen_by_uuid: users(:active).uuid, description: '')
+ proj.update!(frozen_by_uuid: users(:active).uuid, description: '')
end
assert_match /can only be set if description is non-empty/, err.inspect
proj.reload
# Cannot set frozen_by_uuid without properties (if so configured)
Rails.configuration.API.FreezeProjectRequiresProperties['frobity'] = true
err = assert_raises do
- proj.update_attributes!(
+ proj.update!(
frozen_by_uuid: users(:active).uuid,
description: 'ready to freeze')
end
# Cannot set frozen_by_uuid while project or its parent is
# trashed
[parent, proj].each do |trashed|
- trashed.update_attributes!(trash_at: db_current_time)
+ trashed.update!(trash_at: db_current_time)
err = assert_raises do
- proj.update_attributes!(
+ proj.update!(
frozen_by_uuid: users(:active).uuid,
description: 'ready to freeze',
properties: {'frobity' => 'bar baz'})
end
assert_match /cannot be set on a trashed project/, err.inspect
proj.reload
- trashed.update_attributes!(trash_at: nil)
+ trashed.update!(trash_at: nil)
end
# Can set frozen_by_uuid if all conditions are met
- ok = proj.update_attributes(
+ ok = proj.update(
frozen_by_uuid: users(:active).uuid,
description: 'ready to freeze',
properties: {'frobity' => 'bar baz'})
# its descendants
[proj, proj_inner].each do |frozen|
assert_raises do
- collections(:collection_owned_by_active).update_attributes!(owner_uuid: frozen.uuid)
+ collections(:collection_owned_by_active).update!(owner_uuid: frozen.uuid)
end
assert_raises do
Collection.create!(owner_uuid: frozen.uuid, name: 'inside-frozen-project')
# trash, or delete the project or anything beneath it
[proj, proj_inner, coll].each do |frozen|
assert_raises(StandardError, "should reject rename of #{frozen.uuid} (#{frozen.name}) with parent #{frozen.owner_uuid}") do
- frozen.update_attributes!(name: 'foo2')
+ frozen.update!(name: 'foo2')
end
frozen.reload
if frozen.is_a?(Collection)
assert_raises(StandardError, "should reject manifest change of #{frozen.uuid}") do
- frozen.update_attributes!(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n")
+ frozen.update!(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\n")
end
else
assert_raises(StandardError, "should reject moving a project into #{frozen.uuid}") do
- groups(:private).update_attributes!(owner_uuid: frozen.uuid)
+ groups(:private).update!(owner_uuid: frozen.uuid)
end
end
frozen.reload
assert_raises(StandardError, "should reject moving #{frozen.uuid} to a different parent project") do
- frozen.update_attributes!(owner_uuid: groups(:private).uuid)
+ frozen.update!(owner_uuid: groups(:private).uuid)
end
frozen.reload
assert_raises(StandardError, "should reject setting trash_at of #{frozen.uuid}") do
- frozen.update_attributes!(trash_at: db_current_time)
+ frozen.update!(trash_at: db_current_time)
end
frozen.reload
assert_raises(StandardError, "should reject setting delete_at of #{frozen.uuid}") do
- frozen.update_attributes!(delete_at: db_current_time)
+ frozen.update!(delete_at: db_current_time)
end
frozen.reload
assert_raises(StandardError, "should reject delete of #{frozen.uuid}") do
# First confirm we have write permission on the parent project
assert Collection.create(name: 'bar', owner_uuid: parent.uuid)
assert_raises(ArvadosModel::PermissionDeniedError) do
- proj.update_attributes!(frozen_by_uuid: nil)
+ proj.update!(frozen_by_uuid: nil)
end
end
proj.reload
# User with manage permission can unfreeze, then create items
# inside it and its children
- assert proj.update_attributes(frozen_by_uuid: nil)
+ assert proj.update(frozen_by_uuid: nil)
assert Collection.create!(owner_uuid: proj.uuid, name: 'inside-unfrozen-project')
assert Collection.create!(owner_uuid: proj_inner.uuid, name: 'inside-inner-unfrozen-project')
# Re-freeze, and reconfigure so only admins can unfreeze.
- assert proj.update_attributes(frozen_by_uuid: users(:active).uuid)
+ assert proj.update(frozen_by_uuid: users(:active).uuid)
Rails.configuration.API.UnfreezeProjectRequiresAdmin = true
# Owner cannot unfreeze, because not admin.
err = assert_raises do
- proj.update_attributes!(frozen_by_uuid: nil)
+ proj.update!(frozen_by_uuid: nil)
end
assert_match /can only be changed by an admin user, once set/, err.inspect
proj.reload
# Cannot trash or delete a frozen project's ancestor
assert_raises(StandardError, "should not be able to set trash_at on parent of frozen project") do
- parent.update_attributes!(trash_at: db_current_time)
+ parent.update!(trash_at: db_current_time)
end
parent.reload
assert_raises(StandardError, "should not be able to set delete_at on parent of frozen project") do
- parent.update_attributes!(delete_at: db_current_time)
+ parent.update!(delete_at: db_current_time)
end
parent.reload
assert_nil parent.frozen_by_uuid
act_as_user users(:admin) do
# Even admin cannot change frozen_by_uuid to someone else's UUID.
err = assert_raises do
- proj.update_attributes!(frozen_by_uuid: users(:project_viewer).uuid)
+ proj.update!(frozen_by_uuid: users(:project_viewer).uuid)
end
assert_match /can only be set to the current user's UUID/, err.inspect
proj.reload
# Admin can unfreeze.
- assert proj.update_attributes(frozen_by_uuid: nil), proj.errors.messages
+ assert proj.update(frozen_by_uuid: nil), proj.errors.messages
end
# Cannot freeze a project if it contains container requests in
creq_uncommitted = ContainerRequest.create!(test_cr_attrs.merge(owner_uuid: proj_inner.uuid))
creq_committed = ContainerRequest.create!(test_cr_attrs.merge(owner_uuid: proj_inner.uuid, state: 'Committed'))
err = assert_raises do
- proj.update_attributes!(frozen_by_uuid: users(:active).uuid)
+ proj.update!(frozen_by_uuid: users(:active).uuid)
end
assert_match /container request zzzzz-xvhdp-.* with state = Committed/, err.inspect
proj.reload
# Can freeze once all container requests are in Uncommitted or
# Final state
- creq_committed.update_attributes!(state: ContainerRequest::Final)
- assert proj.update_attributes(frozen_by_uuid: users(:active).uuid)
+ creq_committed.update!(state: ContainerRequest::Final)
+ assert proj.update(frozen_by_uuid: users(:active).uuid)
end
end
test "updating permission causes any conflicting links to be deleted" do
link1, link2 = create_overlapping_permissions(['can_read', 'can_manage'])
- Link.find_by_uuid(link2).update_attributes!(name: 'can_write')
+ Link.find_by_uuid(link2).update!(name: 'can_write')
assert_empty Link.where(uuid: link1)
end
test "updating login permission causes any conflicting links to be deleted" do
link1, link2 = create_overlapping_permissions(['can_login', 'can_login'], {properties: {username: 'foo1'}})
- Link.find_by_uuid(link1).update_attributes!(properties: {'username' => 'foo2'})
- Link.find_by_uuid(link2).update_attributes!(properties: {'username' => 'foo2'})
+ Link.find_by_uuid(link1).update!(properties: {'username' => 'foo2'})
+ Link.find_by_uuid(link2).update!(properties: {'username' => 'foo2'})
assert_empty Link.where(uuid: link1)
end
assert_logged(coll, :create) do |props|
assert_equal(txt, props['new_attributes']['manifest_text'])
end
- coll.update_attributes!(name: "testing")
+ coll.update!(name: "testing")
assert_logged(coll, :update) do |props|
assert_equal(txt, props['old_attributes']['manifest_text'])
assert_equal(txt, props['new_attributes']['manifest_text'])
assert(Specimen.where(uuid: i.uuid).any?,
"new item should really be in DB")
- assert(i.update_attributes(owner_uuid: new_o.uuid),
+ assert(i.update(owner_uuid: new_o.uuid),
"should change owner_uuid from #{o.uuid} to #{new_o.uuid}")
end
end
"new #{o_class} should really be in DB")
old_uuid = o.uuid
new_uuid = o.uuid.sub(/..........$/, rand(2**256).to_s(36)[0..9])
- assert(o.update_attributes(uuid: new_uuid),
+ assert(o.update(uuid: new_uuid),
"should change #{o_class} uuid from #{old_uuid} to #{new_uuid}")
assert_equal(false, o_class.where(uuid: old_uuid).any?,
"#{old_uuid} should disappear when renamed to #{new_uuid}")
assert_equal(true, Specimen.where(owner_uuid: o.uuid).any?,
"need something to be owned by #{o.uuid} for this test")
new_uuid = o.uuid.sub(/..........$/, rand(2**256).to_s(36)[0..9])
- assert(!o.update_attributes(uuid: new_uuid),
+ assert(!o.update(uuid: new_uuid),
"should not change uuid of #{ofixt} that owns objects")
end
end
test "delete User that owns self" do
o = User.create!
assert User.where(uuid: o.uuid).any?, "new User should really be in DB"
- assert_equal(true, o.update_attributes(owner_uuid: o.uuid),
+ assert_equal(true, o.update(owner_uuid: o.uuid),
"setting owner to self should work")
skip_check_permissions_against_full_refresh do
assert users(:active).can?(write: ob)
assert users(:active).can?(read: ob)
- l1.update_attributes!(name: 'can_read')
+ l1.update!(name: 'can_read')
assert !users(:active).can?(write: ob)
assert users(:active).can?(read: ob)
"manager saw the minion's private stuff")
assert_raises(ArvadosModel::PermissionDeniedError,
"manager could update minion's private stuff") do
- minions_specimen.update_attributes(properties: {'x' => 'y'})
+ minions_specimen.update(properties: {'x' => 'y'})
end
end
.where(uuid: minions_specimen.uuid),
"manager could not find minion's specimen by uuid")
assert_equal(true,
- minions_specimen.update_attributes(properties: {'x' => 'y'}),
+ minions_specimen.update(properties: {'x' => 'y'}),
"manager could not update minion's specimen object")
end
end
"OTHER can see #{u.first_name} in the user list")
act_as_user u do
assert_raises ArvadosModel::PermissionDeniedError, "wrote without perm" do
- other.update_attributes!(prefs: {'pwned' => true})
+ other.update!(prefs: {'pwned' => true})
end
- assert_equal(true, u.update_attributes!(prefs: {'thisisme' => true}),
+ assert_equal(true, u.update!(prefs: {'thisisme' => true}),
"#{u.first_name} can't update its own prefs")
end
act_as_user other do
assert_raises(ArvadosModel::PermissionDeniedError,
"OTHER wrote #{u.first_name} without perm") do
- u.update_attributes!(prefs: {'pwned' => true})
+ u.update!(prefs: {'pwned' => true})
end
- assert_equal(true, other.update_attributes!(prefs: {'thisisme' => true}),
+ assert_equal(true, other.update!(prefs: {'thisisme' => true}),
"OTHER can't update its own prefs")
end
end
set_user_from_auth :rominiadmin
ob = Collection.create!
assert_raises ArvadosModel::PermissionDeniedError, "changed owner to unwritable user" do
- ob.update_attributes!(owner_uuid: users(:active).uuid)
+ ob.update!(owner_uuid: users(:active).uuid)
end
end
set_user_from_auth :rominiadmin
ob = Collection.create!
assert_raises ArvadosModel::PermissionDeniedError, "changed owner to unwritable group" do
- ob.update_attributes!(owner_uuid: groups(:aproject).uuid)
+ ob.update!(owner_uuid: groups(:aproject).uuid)
end
end
test "non-admin can rename own repo" do
act_as_user users(:active) do
- assert repositories(:foo).update_attributes(name: 'active/foo12345')
+ assert repositories(:foo).update(name: 'active/foo12345')
end
end
if auto_admin_first_user_config
# This test requires no admin users exist (except for the system user)
act_as_system_user do
- users(:admin).update_attributes!(is_admin: false)
+ users(:admin).update!(is_admin: false)
end
@all_users = User.where("uuid not like '%-000000000000000'").where(:is_admin => true)
assert_equal 0, @all_users.count, "No admin users should exist (except for the system user)"
test "empty identity_url saves as null" do
set_user_from_auth :admin
user = users(:active)
- assert user.update_attributes(identity_url: '')
+ assert user.update(identity_url: '')
user.reload
assert_nil user.identity_url
end
definition = "k1:\n v1: x\n v2: y"
assert_raises(ActiveRecord::RecordInvalid) do
- w.update_attributes!(definition: definition)
+ w.update!(definition: definition)
end
end
# when it does not already have custom values for these fields
w = Workflow.find_by_uuid(workflows(:workflow_with_no_name_and_desc).uuid)
definition = "name: test name 1\ndescription: test desc 1\nother: some more"
- w.update_attributes!(definition: definition)
+ w.update!(definition: definition)
w.reload
assert_equal "test name 1", w.name
assert_equal "test desc 1", w.description
# Workflow name and desc should be set with values from definition yaml
# when it does not already have custom values for these fields
definition = "name: test name 2\ndescription: test desc 2\nother: some more"
- w.update_attributes!(definition: definition)
+ w.update!(definition: definition)
w.reload
assert_equal "test name 2", w.name
assert_equal "test desc 2", w.description
# Workflow name and desc should be set with values from definition yaml
# even if it means emptying them out
definition = "more: etc"
- w.update_attributes!(definition: definition)
+ w.update!(definition: definition)
w.reload
assert_nil w.name
assert_nil w.description
# Workflow name and desc set using definition yaml should be cleared
# if definition yaml is cleared
definition = "name: test name 2\ndescription: test desc 2\nother: some more"
- w.update_attributes!(definition: definition)
+ w.update!(definition: definition)
w.reload
definition = nil
- w.update_attributes!(definition: definition)
+ w.update!(definition: definition)
w.reload
assert_nil w.name
assert_nil w.description
# Workflow name and desc should be set to provided custom values
definition = "name: test name 3\ndescription: test desc 3\nother: some more"
- w.update_attributes!(name: "remains", description: "remains", definition: definition)
+ w.update!(name: "remains", description: "remains", definition: definition)
w.reload
assert_equal "remains", w.name
assert_equal "remains", w.description
# Workflow name and desc should retain provided custom values
# and should not be overwritten by values from yaml
definition = "name: test name 4\ndescription: test desc 4\nother: some more"
- w.update_attributes!(definition: definition)
+ w.update!(definition: definition)
w.reload
assert_equal "remains", w.name
assert_equal "remains", w.description
# Workflow name and desc should retain provided custom values
# and not be affected by the clearing of the definition yaml
definition = nil
- w.update_attributes!(definition: definition)
+ w.update!(definition: definition)
w.reload
assert_equal "remains", w.name
assert_equal "remains", w.description