From 3f815e99d301af839deba284aa7c33fed528e04c Mon Sep 17 00:00:00 2001 From: Blanco Date: Wed, 27 Sep 2017 12:26:24 -0400 Subject: [PATCH] for admin_set don't allow title to be editable. --- .../admin/collection_types/_form.html.erb | 20 ++++++++++---- .../_form_metadata_admin_set.html.erb | 2 ++ .../admin/collection_types/index.html.erb | 2 +- .../collection_types/_form.html.erb_spec.rb | 2 ++ .../_form_metadata.html.erb_spec.rb | 3 ++- .../_form_metadata_admin_set.html.erb_spec.rb | 27 +++++++++++++++++++ 6 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 app/views/hyrax/admin/collection_types/_form_metadata_admin_set.html.erb create mode 100644 spec/views/hyrax/admin/collection_types/_form_metadata_admin_set.html.erb_spec.rb diff --git a/app/views/hyrax/admin/collection_types/_form.html.erb b/app/views/hyrax/admin/collection_types/_form.html.erb index 6d8ea03df8..1cdf5379a9 100644 --- a/app/views/hyrax/admin/collection_types/_form.html.erb +++ b/app/views/hyrax/admin/collection_types/_form.html.erb @@ -15,13 +15,23 @@ <% form_url = @form.id.nil? ? hyrax.admin_collection_types_path : hyrax.admin_collection_type_path(@form.id) %> <%= simple_form_for @form, url: form_url, as: :collection_type do |f| %>
-
-
-
- <%= render 'form_metadata', f: f %> + <% if @collection_type.admin_set? %> +
+
+
+ <%= render 'form_metadata_admin_set', f: f %> +
-
+ <% else %> +
+
+
+ <%= render 'form_metadata', f: f %> +
+
+
+ <% end %>
diff --git a/app/views/hyrax/admin/collection_types/_form_metadata_admin_set.html.erb b/app/views/hyrax/admin/collection_types/_form_metadata_admin_set.html.erb new file mode 100644 index 0000000000..597887680e --- /dev/null +++ b/app/views/hyrax/admin/collection_types/_form_metadata_admin_set.html.erb @@ -0,0 +1,2 @@ +<%= f.input :title, :input_html => { :disabled => true } %> +<%= f.input :description, as: :text %> diff --git a/app/views/hyrax/admin/collection_types/index.html.erb b/app/views/hyrax/admin/collection_types/index.html.erb index 849089fbe5..aa6efee474 100644 --- a/app/views/hyrax/admin/collection_types/index.html.erb +++ b/app/views/hyrax/admin/collection_types/index.html.erb @@ -34,7 +34,7 @@ <%= collection_type.title %> - <%= link_to hyrax.edit_admin_collection_type_path(collection_type), class: 'btn btn-primary btn-sm' do %> + <%= link_to hyrax.edit_admin_collection_type_path(collection_type), class: 'btn btn-primary btn-sm', data: { turbolinks: false } do %> <%= t('helpers.action.edit') %> <% end %> <% unless collection_type.admin_set? || collection_type.user_collection? %> diff --git a/spec/views/hyrax/admin/collection_types/_form.html.erb_spec.rb b/spec/views/hyrax/admin/collection_types/_form.html.erb_spec.rb index f965e83f1c..c999c7fe99 100644 --- a/spec/views/hyrax/admin/collection_types/_form.html.erb_spec.rb +++ b/spec/views/hyrax/admin/collection_types/_form.html.erb_spec.rb @@ -1,9 +1,11 @@ RSpec.describe 'hyrax/admin/collection_types/_form.html.erb', type: :view do let(:collection_type) { build(:collection_type) } + # let(:collection_type) { build(:collection_type, machine_id: "type_does_not_matter") } let(:form) { Hyrax::Forms::Admin::CollectionTypeForm.new(collection_type: collection_type) } before do assign(:form, form) + assign(:collection_type, collection_type) end it "has 3 tabs" do diff --git a/spec/views/hyrax/admin/collection_types/_form_metadata.html.erb_spec.rb b/spec/views/hyrax/admin/collection_types/_form_metadata.html.erb_spec.rb index 72d05a3daf..17e124791a 100644 --- a/spec/views/hyrax/admin/collection_types/_form_metadata.html.erb_spec.rb +++ b/spec/views/hyrax/admin/collection_types/_form_metadata.html.erb_spec.rb @@ -1,5 +1,5 @@ RSpec.describe 'hyrax/admin/collection_types/_form_metadata.html.erb', type: :view do - let(:collection_type) { Hyrax::CollectionType.new } + let(:collection_type) { create(:collection_type) } let(:collection_type_form) { Hyrax::Forms::Admin::CollectionTypeForm.new } let(:form) do @@ -17,6 +17,7 @@ it "renders the name field" do expect(rendered).to have_content(I18n.t("simple_form.labels.collection_type.title")) expect(rendered).to have_selector("input#collection_type_title") + expect(rendered).not_to have_css("#collection_type_title[disabled]") end it "renders the description field" do diff --git a/spec/views/hyrax/admin/collection_types/_form_metadata_admin_set.html.erb_spec.rb b/spec/views/hyrax/admin/collection_types/_form_metadata_admin_set.html.erb_spec.rb new file mode 100644 index 0000000000..7bc1c9920f --- /dev/null +++ b/spec/views/hyrax/admin/collection_types/_form_metadata_admin_set.html.erb_spec.rb @@ -0,0 +1,27 @@ +RSpec.describe 'hyrax/admin/collection_types/_form_metadata_admin_set.html.erb', type: :view do + let(:collection_type) { create(:admin_set_collection_type) } + let(:collection_type_form) { Hyrax::Forms::Admin::CollectionTypeForm.new } + + let(:form) do + view.simple_form_for(collection_type, url: '/update') do |fs_form| + return fs_form + end + end + + before do + assign(:form, collection_type_form) + allow(view).to receive(:f).and_return(form) + render + end + + it "renders the name field as readonly" do + expect(rendered).to have_content(I18n.t("simple_form.labels.collection_type.title")) + expect(rendered).to have_selector("input#collection_type_title") + expect(rendered).to have_css("#collection_type_title[disabled]") + end + + it "renders the description field" do + expect(rendered).to have_content(I18n.t("simple_form.labels.collection_type.description")) + expect(rendered).to have_selector("textarea#collection_type_description") + end +end