Skip to content

Commit

Permalink
Pass the proper arguments to boostrap_form_tag. Fixes #39
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Aug 27, 2014
1 parent ac785db commit 63339a9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 25 deletions.
6 changes: 3 additions & 3 deletions app/controllers/concerns/records_controller_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def update

protected

def object_as_json
def object_as_json
# ActiveFedora::Base#to_json causes a circular reference (before 7.0). Do something easy
resource.terms_for_editing.each_with_object({}) { |term, h| h[term] = resource[term] }
resource.terms_for_editing.each_with_object({}) { |term, h| h[term] = resource[term] }
end

# Override this method if you want to set different metadata on the object
Expand Down Expand Up @@ -93,7 +93,7 @@ def has_valid_type?

def initialize_fields
resource.terms_for_editing.each do |key|
# if value is empty, we create an one element array to loop over for output
# if value is empty, we create an one element array to loop over for output
resource[key] = [''] if resource[key].empty?
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/concerns/records_helper_behavior.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'deprecation'
module RecordsHelperBehavior
extend Deprecation

def metadata_help(key)
I18n.t("hydra_editor.form.metadata_help.#{key}", default: key.to_s.humanize)
end
Expand Down
9 changes: 4 additions & 5 deletions app/views/records/choose_type.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<h1><%= t('hydra_editor.choose_type.title') %></h1>
<%= bootstrap_form_tag hydra_editor.new_record_path, :method => :get do |f| %>
<%= bootstrap_select_tag :type, options_for_select(object_type_options) %>
<%= bootstrap_actions do %>
<%= bootstrap_submit_tag 'Next' %>
<% end %>
<%= bootstrap_form_tag url: hydra_editor.new_record_path, method: :get do |f| %>
<label class="control-label" for="type">Select an object type</label>
<%= select_tag :type, options_for_select(object_type_options) %>
<%= f.primary t('hydra_editor.choose_type.next') %>
<% end %>
3 changes: 2 additions & 1 deletion config/locales/hydra_editor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ en:
hydra_editor:
choose_type:
title: 'Create a New Record'
next: 'Next'
edit:
title: 'Edit %s'
form:
title: 'Descriptions'
required_fields: 'indicates required fields'
new:
title: 'Create a New %s Record'
title: 'Create a New %s Record'
28 changes: 28 additions & 0 deletions spec/features/create_record_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'spec_helper'

feature 'User creates an object' do
let(:user) { FactoryGirl.create(:user) }

before do
HydraEditor.models = ['Audio']
login_as user
# since we're stubbing save, we won't have an id to redirect to.
allow_any_instance_of(RecordsController).to receive(:redirect_after_create).and_return("/404.html")
end

scenario 'with a TuftsAudio' do
visit '/records/new'

select "Audio", from: 'Select an object type'
click_button 'Next'

fill_in '*Title', with: 'My title'

expect_any_instance_of(Audio).to receive(:attributes=).with({}) # called when initializing a new object
expect_any_instance_of(Audio).to receive(:attributes=).with(title: ["My title"])
# Avoid the catalog so we don't have to run Solr
expect_any_instance_of(Audio).to receive(:save).and_return(true)
click_button 'Save'
end

end
30 changes: 15 additions & 15 deletions spec/features/record_editing_spec.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
require 'spec_helper'

describe "record editing" do
let(:user) { FactoryGirl.create(:user) }
let(:record) { Audio.new(pid: "foo:1", title: "Cool Track") }
# We need a clone to give to the edit view b/c it gets changed by initialize_fields
let(:record_clone) { Audio.new(pid: "foo:1", title: "Cool Track") }

before do
HydraEditor.models = ['Audio']
@user = FactoryGirl.create(:user)
@ability = double(Ability)
@ability.stub(:authorize!).and_return(true)
Ability.stub(:new).with(@user).and_return(@ability)
allow_any_instance_of(Ability).to receive(:authorize!).and_return(true)
# Avoid the catalog so we don't have to run Solr
allow_any_instance_of(RecordsController).to receive(:redirect_after_update).and_return("/404.html")
allow_any_instance_of(Audio).to receive(:persisted?).and_return(true)
allow_any_instance_of(Audio).to receive(:new_record?).and_return(false)
allow_any_instance_of(Audio).to receive(:save).and_return(true)
@record = Audio.new(pid: "foo:1", title: "Cool Track")
# We need a clone to give to the edit view b/c it gets changed by initialize_fields
@record_clone = Audio.new(pid: "foo:1", title: "Cool Track")

# We use the original record for the update view to start clean and apply the form data
ActiveFedora::Base.should_receive(:find).with(@record.pid, cast: true).and_return(@record_clone, @record)
login_as @user
expect(ActiveFedora::Base).to receive(:find).with(record.pid, cast: true).and_return(record_clone, record)
login_as user
end

after do
Warden.test_reset!
end
it "should be idempotent" do
visit "/records/#{@record.pid}/edit"
visit "/records/#{record.pid}/edit"
click_button 'Save'
@record.title.should == ["Cool Track"]
@record.creator.should == []
@record.description.should == []
@record.subject.should == []
expect(record.title).to eq ["Cool Track"]
expect(record.creator).to eq []
expect(record.description).to eq []
expect(record.subject).to eq []
end
end

0 comments on commit 63339a9

Please sign in to comment.