Skip to content

Commit

Permalink
allow changing of client_type via api
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jul 28, 2019
1 parent cb5eba8 commit 13be6af
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 41 deletions.
4 changes: 2 additions & 2 deletions app/controllers/periodicals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion spec/requests/periodicals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
6 changes: 4 additions & 2 deletions spec/requests/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" => {
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
33 changes: 0 additions & 33 deletions spec/routing/organizations_routing_spec.rb

This file was deleted.

0 comments on commit 13be6af

Please sign in to comment.