Skip to content
This repository has been archived by the owner on Jul 31, 2019. It is now read-only.

Commit

Permalink
Makes :title accesible on Worthwhile::GenericFile so that the Title f…
Browse files Browse the repository at this point in the history
…ield on GenericFile create/update form actually gets applied to the GenericFile object

refs #34
  • Loading branch information
flyingzumwalt committed Nov 11, 2014
1 parent d56537e commit 3aeb2a3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,17 @@
end

context "updating metadata" do
it "should be successful" do
it "should be successful and update attributes" do
post :update, id: generic_file, generic_file:
{title: 'new_title', tag: [''], permissions: { new_user_name: {'archivist1'=>'edit'}}}
expect(response).to redirect_to [:curation_concern, generic_file]
expect(assigns[:generic_file].title).to eq(['new_title'])
end

it "should go back to edit on an error" do
allow_any_instance_of(Worthwhile::GenericFile).to receive(:valid?).and_return(false)
post :update, id: generic_file, generic_file:
{title: 'new_title', tag: [''], permissions: { new_user_name: {'archivist1'=>'edit'}}}
{title: ['new_title'], tag: [''], permissions: { new_user_name: {'archivist1'=>'edit'}}}
expect(response).to be_successful
expect(response).to render_template('edit')
expect(assigns[:generic_file]).to eq generic_file
Expand All @@ -150,7 +151,7 @@
it "should add a new groups and users" do
skip
post :update, id: generic_file, generic_file:
{ title: 'new_title', tag: [''], permissions: { new_group_name: {'group1'=>'read'}, new_user_name: {'user1'=>'edit'}}}
{ title: ['new_title'], tag: [''], permissions: { new_group_name: {'group1'=>'read'}, new_user_name: {'user1'=>'edit'}}}

expect(assigns[:generic_file].read_groups).to eq ["group1"]
expect(assigns[:generic_file].edit_users).to include("user1", @user.user_key)
Expand All @@ -161,7 +162,7 @@
generic_file.read_groups = ['group3']
generic_file.save! # TODO slow test, more than one save.
post :update, id: generic_file, generic_file:
{ title: 'new_title', tag: [''], permissions: { new_group_name: '', new_user_name: '', group: {'group3' => 'read' }}}
{ title: ['new_title'], tag: [''], permissions: { new_group_name: '', new_user_name: '', group: {'group3' => 'read' }}}
expect(assigns[:generic_file].read_groups).to eq ["group3"]
end

Expand Down
5 changes: 5 additions & 0 deletions spec/models/worthwhile/generic_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
subject.depositor = '[email protected]'
end

it "should update attributes" do
subject.attributes = {title:["My new Title"]}
expect(subject.title).to eq(["My new Title"])
end

describe "to_solr" do
before do
subject.title = ['One Flew Over the Cuckoo\'s Nest']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module GenericFileBase

attr_accessor :file

attr_accessible *(terms_for_display)

# make filename single-value (Sufia::GenericFile::Characterization makes it multivalue)
# has_attributes :filename, datastream: :characterization, multiple: false
def filename
Expand Down

0 comments on commit 3aeb2a3

Please sign in to comment.