diff --git a/app/controllers/periodicals_controller.rb b/app/controllers/periodicals_controller.rb index 8836b3078..b42ac36f5 100644 --- a/app/controllers/periodicals_controller.rb +++ b/app/controllers/periodicals_controller.rb @@ -89,7 +89,7 @@ def show def create logger = Logger.new(STDOUT) - @client = Client.new(safe_params.merge(client_type: "periodical")) + @client = Client.new(safe_params) authorize! :create, @client if @client.save @@ -105,7 +105,7 @@ def create def update logger = Logger.new(STDOUT) - if @client.update_attributes(safe_params.merge(client_type: "periodical")) + if @client.update_attributes(safe_params) options = {} options[:meta] = { dois: doi_count(client_id: params[:id]) } options[:is_collection] = false diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 05e5542c8..d606068db 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -102,7 +102,7 @@ def show def create logger = Logger.new(STDOUT) - @client = Client.new(safe_params.merge(client_type: "repository")) + @client = Client.new(safe_params) authorize! :create, @client if @client.save @@ -118,7 +118,7 @@ def create def update logger = Logger.new(STDOUT) - if @client.update_attributes(safe_params.merge(client_type: "repository")) + if @client.update_attributes(safe_params) options = {} options[:meta] = { dois: doi_count(client_id: params[:id]) } options[:is_collection] = false diff --git a/app/models/client.rb b/app/models/client.rb index 3e5550498..7444251e4 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -35,7 +35,7 @@ class Client < ActiveRecord::Base validates_uniqueness_of :symbol, message: "This Client ID has already been taken" validates_format_of :contact_email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i validates_inclusion_of :role_name, :in => %w( ROLE_DATACENTRE ), :message => "Role %s is not included in the list" - validates_inclusion_of :client_type, :in => %w( repository periodical ), :message => "Client type %s is not included in the list", if: :client_type? + validates_inclusion_of :client_type, :in => %w( repository periodical ), :message => "Client type %s is not included in the list" validates_associated :provider validate :check_id, :on => :create validate :freeze_symbol, :on => :update diff --git a/spec/requests/periodicals_spec.rb b/spec/requests/periodicals_spec.rb index b4fe16e90..5b2891297 100644 --- a/spec/requests/periodicals_spec.rb +++ b/spec/requests/periodicals_spec.rb @@ -170,7 +170,8 @@ let(:params) do { "data" => { "type" => "periodicals", "attributes" => { - "name" => "Imperial College 2"}} } + "name" => "Imperial College 2", + "clientType" => "repository"}} } end it 'updates the record' do @@ -179,6 +180,7 @@ expect(last_response.status).to eq(200) expect(json.dig('data', 'attributes', 'name')).to eq("Imperial College 2") expect(json.dig('data', 'attributes', 'name')).not_to eq(client.name) + expect(json.dig('data', 'attributes', 'clientType')).to eq("repository") end end diff --git a/spec/requests/repositories_spec.rb b/spec/requests/repositories_spec.rb index 394a980cd..6161e60ab 100644 --- a/spec/requests/repositories_spec.rb +++ b/spec/requests/repositories_spec.rb @@ -4,7 +4,7 @@ let(:ids) { clients.map { |c| c.uid }.join(",") } let(:bearer) { User.generate_token } let(:provider) { create(:provider, password_input: "12345") } - let!(:client) { create(:client, provider: provider) } + let!(:client) { create(:client, provider: provider, client_type: "repository") } let(:params) do { "data" => { "type" => "clients", "attributes" => { @@ -142,7 +142,8 @@ let(:params) do { "data" => { "type" => "repositories", "attributes" => { - "name" => "Imperial College 2"}} } + "name" => "Imperial College 2", + "clientType" => "periodical" }} } end it 'updates the record' do @@ -151,6 +152,7 @@ expect(last_response.status).to eq(200) expect(json.dig('data', 'attributes', 'name')).to eq("Imperial College 2") expect(json.dig('data', 'attributes', 'name')).not_to eq(client.name) + expect(json.dig('data', 'attributes', 'clientType')).to eq("periodical") end end diff --git a/spec/routing/organizations_routing_spec.rb b/spec/routing/organizations_routing_spec.rb deleted file mode 100644 index 04e72c9fc..000000000 --- a/spec/routing/organizations_routing_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require "rails_helper" - -describe ProvidersController, type: :routing do - describe "routing" do - - it "routes to #index" do - expect(:get => "/providers").to route_to("providers#index") - end - - - it "routes to #show" do - expect(:get => "/providers/1").to route_to("providers#show", :id => "1") - end - - - it "routes to #create" do - expect(:post => "/providers").to route_to("providers#create") - end - - it "routes to #update via PUT" do - expect(:put => "/providers/1").to route_to("providers#update", :id => "1") - end - - it "routes to #update via PATCH" do - expect(:patch => "/providers/1").to route_to("providers#update", :id => "1") - end - - it "routes to #destroy" do - expect(:delete => "/providers/1").to route_to("providers#destroy", :id => "1") - end - - end -end