diff --git a/app/jobs/target_doi_by_id_job.rb b/app/jobs/target_doi_by_id_job.rb index f908064f1..b641893a7 100644 --- a/app/jobs/target_doi_by_id_job.rb +++ b/app/jobs/target_doi_by_id_job.rb @@ -10,6 +10,7 @@ def perform(id, options={}) return false if item.blank? item.set_source_and_target_doi + if item.save Rails.logger.info "Target doi for #{item.uuid} updated." else diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index 1eb395685..dab153272 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -451,11 +451,11 @@ def create_index self.__elasticsearch__.create_index!(index: index_name) unless self.__elasticsearch__.index_exists?(index: index_name) self.__elasticsearch__.create_index!(index: alternate_index_name) unless self.__elasticsearch__.index_exists?(index: alternate_index_name) - + # index_name is the active index client = Elasticsearch::Model.client client.indices.put_alias index: index_name, name: alias_name unless client.indices.exists_alias?(name: alias_name) - + "Created indexes #{index_name} (active) and #{alternate_index_name}." end diff --git a/app/models/doi.rb b/app/models/doi.rb index fe9d06bca..d108eb6dc 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -80,7 +80,8 @@ class Doi < ActiveRecord::Base has_many :part_of, -> { where target_relation_type_id: "part_of" }, class_name: "Event", primary_key: :doi, foreign_key: :target_doi, dependent: :destroy has_many :versions, -> { where source_relation_type_id: "versions" }, class_name: "Event", primary_key: :doi, foreign_key: :source_doi, dependent: :destroy has_many :version_of, -> { where target_relation_type_id: "version_of" }, class_name: "Event", primary_key: :doi, foreign_key: :target_doi, dependent: :destroy - + has_many :activities, foreign_key: :auditable_id, dependent: :destroy + delegate :provider, to: :client, allow_nil: true delegate :consortium_id, to: :provider, allow_nil: true diff --git a/app/models/provider.rb b/app/models/provider.rb index 5698eda1c..e52adaf2a 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -1,7 +1,6 @@ require "countries" class Provider < ActiveRecord::Base - # include helper module for caching infrequently changing resources include Cacheable diff --git a/config/routes.rb b/config/routes.rb index 7b7a0925d..da9f6bb61 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,13 +2,13 @@ post "/client-api/graphql", to: "graphql#execute" get "/client-api/graphql", to: "index#method_not_allowed" - root :to => 'index#index' + root to: "index#index" # authentication - post 'token', :to => 'sessions#create_token' + post "token", to: "sessions#create_token" # authentication via openid connect in load balancer - post 'oidc-token', :to => 'sessions#create_oidc_token' + post "oidc-token", to: "sessions#create_oidc_token" # send reset link post 'reset', :to => 'sessions#reset' diff --git a/spec/jobs/event_registrant_update_by_id_job_spec.rb b/spec/jobs/event_registrant_update_by_id_job_spec.rb new file mode 100644 index 000000000..99392798d --- /dev/null +++ b/spec/jobs/event_registrant_update_by_id_job_spec.rb @@ -0,0 +1,16 @@ +require "rails_helper" + +describe EventRegistrantUpdateByIdJob, type: :job do + let(:event) { create(:event) } + subject(:job) { EventRegistrantUpdateByIdJob.perform_later(event.uuid) } + + it "queues the job" do + expect { job }.to have_enqueued_job(EventRegistrantUpdateByIdJob) + .on_queue("test_lupo_background") + end + + after do + clear_enqueued_jobs + clear_performed_jobs + end +end diff --git a/spec/jobs/event_update_by_id_job.rb b/spec/jobs/event_update_by_id_job.rb deleted file mode 100644 index e996a9c0b..000000000 --- a/spec/jobs/event_update_by_id_job.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'rails_helper' - -describe EventUpdateByIdJob, type: :job do - let(:event) { create(:event) } - subject(:job) { EventUpdateByIdJob.perform_later(event.uuid) } - - it 'queues the job' do - expect { job }.to have_enqueued_job(EventUpdateByIdJob) - .on_queue("test_lupo_background") - end - - after do - clear_enqueued_jobs - clear_performed_jobs - end -end diff --git a/spec/jobs/index_background_job_spec.rb b/spec/jobs/index_background_job_spec.rb new file mode 100644 index 000000000..2694fe523 --- /dev/null +++ b/spec/jobs/index_background_job_spec.rb @@ -0,0 +1,16 @@ +require "rails_helper" + +describe IndexBackgroundJob, type: :job do + let(:doi) { create(:doi) } + subject(:job) { IndexBackgroundJob.perform_later(doi) } + + it "queues the job" do + expect { job }.to have_enqueued_job(IndexBackgroundJob) + .on_queue("test_lupo_background").at_least(1).times + end + + after do + clear_enqueued_jobs + clear_performed_jobs + end +end diff --git a/spec/jobs/index_job_spec.rb b/spec/jobs/index_job_spec.rb index 93daa32d5..cb64beef2 100644 --- a/spec/jobs/index_job_spec.rb +++ b/spec/jobs/index_job_spec.rb @@ -1,10 +1,10 @@ -require 'rails_helper' +require "rails_helper" describe IndexJob, type: :job do let(:doi) { create(:doi) } subject(:job) { IndexJob.perform_later(doi) } - it 'queues the job' do + it "queues the job" do expect { job }.to have_enqueued_job(IndexJob) .on_queue("test_lupo").at_least(1).times end @@ -13,4 +13,4 @@ clear_enqueued_jobs clear_performed_jobs end -end \ No newline at end of file +end diff --git a/spec/jobs/target_doi_by_id_job_spec.rb b/spec/jobs/target_doi_by_id_job_spec.rb new file mode 100644 index 000000000..d5d70e0aa --- /dev/null +++ b/spec/jobs/target_doi_by_id_job_spec.rb @@ -0,0 +1,16 @@ +require "rails_helper" + +describe TargetDoiByIdJob, type: :job do + let(:doi) { create(:doi) } + subject(:job) { TargetDoiByIdJob.perform_later(doi) } + + it "queues the job" do + expect { job }.to have_enqueued_job(TargetDoiByIdJob) + .on_queue("test_lupo_background").at_least(1).times + end + + after do + clear_enqueued_jobs + clear_performed_jobs + end +end diff --git a/spec/jobs/update_state_job.rb b/spec/jobs/update_state_job_spec.rb similarity index 85% rename from spec/jobs/update_state_job.rb rename to spec/jobs/update_state_job_spec.rb index 11c681b42..c51556648 100644 --- a/spec/jobs/update_state_job.rb +++ b/spec/jobs/update_state_job_spec.rb @@ -1,10 +1,10 @@ -require 'rails_helper' +require "rails_helper" describe UpdateStateJob, type: :job do let(:doi) { create(:doi) } subject(:job) { UpdateStateJob.perform_later(doi.doi) } - it 'queues the job' do + it "queues the job" do expect { job }.to have_enqueued_job(UpdateStateJob) .on_queue("test_lupo_background") end @@ -13,4 +13,4 @@ clear_enqueued_jobs clear_performed_jobs end -end \ No newline at end of file +end diff --git a/spec/models/client_spec.rb b/spec/models/client_spec.rb index 289d84ff9..7579f4977 100644 --- a/spec/models/client_spec.rb +++ b/spec/models/client_spec.rb @@ -1,8 +1,8 @@ -require 'rails_helper' +require "rails_helper" describe Client, type: :model do - let(:provider) { create(:provider) } - let(:client) { create(:client, provider: provider) } + let(:provider) { create(:provider) } + let(:client) { create(:client, provider: provider) } describe "Validations" do it { should validate_presence_of(:symbol) } diff --git a/spec/models/doi_spec.rb b/spec/models/doi_spec.rb index e87439b77..adcc358e3 100644 --- a/spec/models/doi_spec.rb +++ b/spec/models/doi_spec.rb @@ -606,7 +606,8 @@ describe "citations", elasticsearch: true do let(:client) { create(:client) } let(:doi) { create(:doi, client: client, aasm_state: "findable") } - let!(:citations) { create_list(:event_for_datacite_crossref, 1, subj_id: "https://doi.org/#{doi.doi}", relation_type_id: "is-referenced-by") } + let(:source_doi) { create(:doi, client: client, aasm_state: "findable") } + let!(:citations) { create_list(:event_for_datacite_crossref, 1, subj_id: "https://doi.org/#{doi.doi}", obj_id: "https://doi.org/#{source_doi.doi}", relation_type_id: "is-referenced-by") } before do Doi.import diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 0ddd279f2..95b03cc78 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -1,6 +1,6 @@ -require 'rails_helper' +require "rails_helper" -describe Event, :type => :model, vcr: true do +describe Event, type: :model, vcr: true do before(:each) { allow(Time.zone).to receive(:now).and_return(Time.mktime(2015, 4, 8)) } context "event" do subject { create(:event) } @@ -16,15 +16,15 @@ context "citation" do subject { create(:event_for_datacite_related) } - + it "has citation_id" do expect(subject.citation_id).to eq("https://doi.org/10.5061/dryad.47sd5/1-https://doi.org/10.5061/dryad.47sd5e/1") end - + it "has citation_year" do expect(subject.citation_year).to eq(2015) end - + it "has published_dates" do expect(subject.subj["datePublished"]).to eq("2006-06-13T16:14:19Z") expect(subject.obj["datePublished"]).to be_nil @@ -33,7 +33,7 @@ let(:doi) { create(:doi) } it "date_published from the database" do - published = subject.date_published("https://doi.org/"+doi.doi) + published = subject.date_published("https://doi.org/" + doi.doi) expect(published).to eq("2011") expect(published).not_to eq(2011) end diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index 54ebc093c..8a9e0cd97 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" describe "dois", type: :request do let(:admin) { create(:provider, symbol: "ADMIN") } @@ -14,7 +14,7 @@ let(:bearer) { Client.generate_token(role_id: "client_admin", uid: client.symbol, provider_id: provider.symbol.downcase, client_id: client.symbol.downcase, password: client.password) } let(:headers) { { 'HTTP_ACCEPT'=>'application/vnd.api+json', 'HTTP_AUTHORIZATION' => 'Bearer ' + bearer }} - describe 'GET /dois', elasticsearch: true do + describe "GET /dois", elasticsearch: true do let!(:dois) { create_list(:doi, 3, client: client, aasm_state: "findable") } before do @@ -23,7 +23,7 @@ end it 'returns dois', vcr: true do - get '/dois', nil, headers + get "/dois", nil, headers expect(last_response.status).to eq(200) expect(json['data'].size).to eq(3) diff --git a/spec/support/elasticsearch_helper.rb b/spec/support/elasticsearch_helper.rb index a4d4ecdd3..6702b97cb 100644 --- a/spec/support/elasticsearch_helper.rb +++ b/spec/support/elasticsearch_helper.rb @@ -1,5 +1,5 @@ ## https://github.com/elastic/elasticsearch-ruby/issues/462 -SEARCHABLE_MODELS = [Client, Provider, Doi, Event] +SEARCHABLE_MODELS = [Client, Provider, Doi, Event, Activity] RSpec.configure do |config| config.around :all, elasticsearch: true do |example|