This repository has been archived by the owner on Nov 20, 2019. It is now read-only.
forked from CDLUC3/dashv2
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from CDL-Dryad/versioning-display2
Versioning display UI elements
- Loading branch information
Showing
11 changed files
with
156 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,3 +75,4 @@ deploy script will prompt you. | |
``` | ||
bundle exec rake app_data:clear RAILS_ENV=<rails-environment> | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
FactoryBot.define do | ||
|
||
factory :share, class: StashEngine::Share do | ||
resource | ||
identifier | ||
|
||
secret_id { SecureRandom.uuid } | ||
|
||
transient do | ||
tenant { 'dryad' } | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FactoryBot.define do | ||
|
||
factory :version, class: StashEngine::Version do | ||
resource | ||
version { 1 } | ||
merritt_version { 1 } | ||
zip_filename { nil } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'byebug' | ||
|
||
# see https://relishapp.com/rspec/rspec-rails/v/3-8/docs/request-specs/request-spec | ||
# rubocop:disable Metrics/BlockLength | ||
module StashEngine | ||
RSpec.describe LandingController, type: :request do | ||
|
||
include MerrittHelper | ||
include DatasetHelper | ||
include DatabaseHelper | ||
include Mocks::Datacite | ||
include Mocks::Repository | ||
include Mocks::RSolr | ||
include Mocks::Ror | ||
include Mocks::Stripe | ||
|
||
before(:each) do | ||
# kind of crazy to mock all this, but creating identifiers and the curation activity of published triggers all sorts of stuff | ||
mock_repository! | ||
mock_solr! | ||
mock_ror! | ||
mock_datacite! | ||
mock_stripe! | ||
|
||
# below will create @identifier, @resource, @user and the basic required things for an initial version of a dataset | ||
create_basic_dataset! | ||
end | ||
|
||
it 'creates basic_dataset that is valid with required metadata with factory bot' do | ||
expect(@resource.identifier).to eq(@identifier) | ||
expect(@resource.authors.count.positive?).to eq(true) | ||
expect(@resource.descriptions).to have(1).items | ||
expect(@resource.authors.first.affiliations).to have(1).items | ||
expect(@resource.current_resource_state.resource_state).to eq('submitted') | ||
expect(@resource.curation_activities.last.status).to eq('submitted') | ||
expect(@resource.stash_version.version).to eq(1) | ||
expect(@resource.stash_version.merritt_version).to eq(1) | ||
expect(@resource.file_uploads).to have(1).item | ||
end | ||
|
||
it 'duplicates the basic dataset for version 2 with metadata' do | ||
duplicate_resource!(resource: @identifier.resources.last) | ||
@identifier.reload | ||
expect(@identifier.resources).to have(2).items | ||
res = @identifier.resources.last | ||
@identifier.reload | ||
expect(res.stash_version.version).to eq(2) | ||
expect(res.stash_version.merritt_version).to eq(2) | ||
# this file was copied over from a previous version and isn't a new file | ||
expect(res.file_uploads.first.file_state).to eq('copied') | ||
expect(res.file_uploads.first.upload_file_name).to eq(@resource.file_uploads.first.upload_file_name) | ||
end | ||
|
||
it "doesn't show a submitted but not embargoed/published version of the landing page" do | ||
get "/stash/dataset/#{@identifier}" | ||
expect(response).to have_http_status(:not_found) | ||
end | ||
|
||
it 'shows version of the dataset marked for metadata view' do | ||
# make first look embargoed and second isn't yet | ||
res = @identifier.resources.first | ||
res.update(meta_view: true, publication_date: Time.new + 1.day) | ||
@identifier.update(pub_state: 'embargoed') | ||
create(:curation_activity, status: 'embargoed', user_id: @user.id, resource_id: res.id) | ||
|
||
# 2nd resource not seen yet | ||
duplicate_resource!(resource: @identifier.resources.last) | ||
res2 = @identifier.resources.last | ||
res2.update(title: 'Treecats and friends') | ||
@identifier.reload | ||
|
||
get "/stash/dataset/#{@identifier}" | ||
expect(response.body).to include(res.title) | ||
expect(response.body).not_to include(res2.title) | ||
expect(response.body).to include('This dataset is embargoed') | ||
end | ||
|
||
it 'shows version of the dataset marked as published' do | ||
# make first look embargoed and second isn't yet | ||
res = @identifier.resources.first | ||
res.update(meta_view: true, file_view: true, publication_date: Time.new) | ||
@identifier.update(pub_state: 'published') | ||
create(:curation_activity, status: 'published', user_id: @user.id, resource_id: res.id) | ||
|
||
# 2nd resource not seen yet | ||
duplicate_resource!(resource: @identifier.resources.last) | ||
res2 = @identifier.resources.last | ||
res2.update(title: 'Treecats and friends') | ||
create(:file_upload, resource_id: res2.id, file_state: 'created') | ||
@identifier.reload | ||
|
||
get "/stash/dataset/#{@identifier}" | ||
expect(response.body).to include(res.title) | ||
expect(response.body).not_to include(res2.title) | ||
expect(response.body).not_to include('This dataset is embargoed') | ||
expect(response.body).to include(res.file_uploads.first.upload_file_name) | ||
# shows old file, but not new file that isn't published yet | ||
expect(response.body).not_to include(res2.file_uploads.where(file_state: 'created').first.upload_file_name) | ||
end | ||
|
||
end | ||
end | ||
# rubocop:enable Metrics/BlockLength |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# this is a helper to create states in the database for seeing specific display states, mostly on the landing page responses | ||
|
||
module DatabaseHelper | ||
|
||
def create_basic_dataset! | ||
@user = create(:user, role: 'superuser') | ||
@identifier = create(:identifier) | ||
@resource = create(:resource, :submitted, identifier: @identifier, user_id: @user.id, tenant_id: @user.tenant_id, | ||
authors: [create(:author)], descriptions: [create(:description)], | ||
stash_version: create(:version, version: 1, merritt_version: 1), | ||
file_uploads: [create(:file_upload)]) | ||
end | ||
|
||
# this essentially creates a new resource (version) to start working on for a user | ||
def duplicate_resource!(resource:, user: nil) | ||
new_res = resource.amoeba_dup | ||
# TODO: we need to upgrade the version Rubocop uses to Ruby 2.4 in this repo config, but it destroys lots of auto-generated | ||
# code if I run rubocop -a with it upgraded so avoiding the upgrade for now. (this used to use the &. construct ) | ||
new_res.current_editor_id = (user ? user.id : resource.user_id) | ||
|
||
new_res.curation_activities.update_all(user_id: user.id) if user | ||
new_res.save! | ||
end | ||
end |