Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/jobs/load_big_sam_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class LoadBigSamJob < ApplicationJob
queue_as :default

def perform(*args)
FileUtils.touch('big_sam_loading')
FileUtils.touch('big_sam_loading') unless ENV['RAILS_ENV'] == 'test'
logger.debug 'starting big sam load'

big_sam = args.first
Expand Down
2 changes: 1 addition & 1 deletion app/models/letter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def all_entities
private

def check_published
self.published = repositories.any?(&:published)
self.published = repositories.any?(&:published) || letter_publisher.present?
end

def reindex_published
Expand Down
1 change: 1 addition & 0 deletions spec/factories/letters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

factory :unpublished_letter do
repositories { create_list(:repository, 1, published: false) }
letter_publisher { nil }
end

factory :new_letter do
Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/load_big_sam_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
big_sam_file = fixture_file_upload('big_sam.xlsx')
create(:big_sam, big_sam: big_sam_file)
Letter.find_each(&:save)
expect(Letter.published.count).to eq(18)
expect(Letter.published.count).to eq(19)
expect(Repository.count).to eq(7)
expect(Repository.published.count).to eq(4)
end
Expand Down
20 changes: 13 additions & 7 deletions spec/models/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
include ActionView::Helpers::SanitizeHelper
include ActiveSupport::Inflector

it 'creates a hash of pubically avaliable letters where entity is mentioned' do
it 'creates a hash of publicly avaliable letters where entity is mentioned' do
entity = create(:place_entity)

create_list(:letter, 5)
Expand All @@ -19,7 +19,8 @@
4,
date: Faker::Date.between(from: '1900-1-1', to: '1930-1-1'),
repositories: create_list(:repository, 1, published: true),
entities: [entity]
entities: [entity],
letter_publisher: nil
)

create_list(
Expand All @@ -28,7 +29,8 @@
date: Faker::Date.between(from: '1957-1-1', to: '1965-12-31'),
repositories: create_list(:repository, 1, published: true),
destinations: [entity],
recipients: create_list(:person_entity, 2)
recipients: create_list(:person_entity, 2),
letter_publisher: nil
)

create_list(
Expand All @@ -37,7 +39,8 @@
date: Faker::Date.between(from: '1957-1-1', to: '1965-12-31'),
repositories: create_list(:repository, 1, published: true),
origins: [entity],
recipients: create_list(:person_entity, 2)
recipients: create_list(:person_entity, 2),
letter_publisher: nil
)

create_list(
Expand All @@ -46,15 +49,17 @@
date: Faker::Date.between(from: '1957-1-1', to: '1965-12-31'),
repositories: create_list(:repository, 1, published: true),
entities: [entity],
recipients: create_list(:person_entity, 2)
recipients: create_list(:person_entity, 2),
letter_publisher: nil
)

create_list(
:letter,
2,
date: Faker::Date.between(from: '1957-1-1', to: '1965-12-31'),
repositories: create_list(:repository, 1, published: false),
entities: [entity]
entities: [entity],
letter_publisher: nil
)

create_list(
Expand All @@ -63,7 +68,8 @@
date: Faker::Date.between(from: '1966-1-1', to: '2000-12-31'),
repositories: create_list(:repository, 1, published: false),
destinations: [entity],
recipients: create_list(:person_entity, 2)
recipients: create_list(:person_entity, 2),
letter_publisher: nil
)

expect(entity.all_letters.count).to be < Letter.count
Expand Down
21 changes: 16 additions & 5 deletions spec/models/letter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,43 @@
:letter,
4,
date: Faker::Date.between(from: '1900-1-1', to: '1930-1-1'),
repositories: create_list(:repository, 1, published: true)
repositories: create_list(:repository, 1, published: true),
letter_publisher: nil
)

create_list(
:letter,
6,
date: Faker::Date.between(from: '1957-1-1', to: '1965-12-31'),
repositories: create_list(:repository, 1, published: true)
repositories: create_list(:repository, 1, published: true),
letter_publisher: nil
)

create_list(
:letter,
2,
date: Faker::Date.between(from: '1957-1-1', to: '1965-12-31'),
repositories: create_list(:repository, 1, published: false)
repositories: create_list(:repository, 1, published: false),
letter_publisher: nil
)

create_list(
:letter,
3,
date: Faker::Date.between(from: '1966-1-1', to: '2000-12-31'),
repositories: create_list(:repository, 1, published: false),
letter_publisher: nil
)

create_list(
:letter,
2,
date: Faker::Date.between(from: '1957-1-1', to: '1965-12-31'),
repositories: create_list(:repository, 1, published: false)
)

expect(described_class.count).to eq(15)
expect(described_class.published.count).to eq(10)
expect(described_class.count).to eq(17)
expect(described_class.published.count).to eq(12)
end

it 'has distinct mentions' do
Expand Down
1 change: 1 addition & 0 deletions spec/models/published_entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
entity.save!
expect(described_class.search('*', where: { label: entity.label }).first.id).to eq(entity.id)
entity.letters.first.repositories.first.update(published: false)
entity.letters.first.update(letter_publisher: nil)
entity.letters.first.save
entity.save!
entity.reload
Expand Down
4 changes: 2 additions & 2 deletions spec/models/published_letter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
RSpec.describe PublishedLetter do
it 'only returns published entities' do
create_list(:published_letter, 5)
create_list(:letter, 3, published: false)
create_list(:letter, 3, published: false, letter_publisher: nil)

expect(described_class.all.map(&:published)).to all(be true)
expect(described_class.count).to be < Letter.count
Expand All @@ -23,7 +23,7 @@
end

it 'updates index when letter is unpublished' do
letter = create(:published_letter)
letter = create(:published_letter, letter_publisher: nil)
expect(described_class.search('*', where: { label: letter.label }).first.id).to eq(letter.id)
letter.repositories.first.update(published: false)
letter.save!
Expand Down
2 changes: 1 addition & 1 deletion spec/models/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
RSpec.describe Repository do
it 'updates entity and letter published status' do
repo = create(:repository, published: false)
create_list(:letter, 3, repositories: [repo])
create_list(:letter, 3, repositories: [repo], letter_publisher: nil)
expect(repo.letters.count).to eq(3)
expect(repo.letters.map(&:published)).to all(be false)
repo.letters.each do |letter|
Expand Down
17 changes: 12 additions & 5 deletions spec/requests/letters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
expect(response).to be_successful
end

it 'renders only plblically avaliable letters' do
it 'renders only publicly available letters' do
create_list(:published_letter, 4)
create_list(:letter, 3, repositories: create_list(:repository, 1, published: false))
create_list(:new_letter, 5, repositories: create_list(:repository, 1, published: false))
create_list(:letter, 3, repositories: create_list(:repository, 1, published: false), letter_publisher: nil)
create_list(:new_letter, 5, repositories: create_list(:repository, 1, published: false), letter_publisher: nil)
get "#{letters_url}.json", headers: valid_headers, as: :json
expect(Letter.published.count).to eq(4)
expect(json[:letters].count).to eq(4)
Expand Down Expand Up @@ -163,15 +163,22 @@
expect(response).to be_successful
end

it 'does not include private repositories when letter previously published' do
letter = create(:letter, repositories: [create(:repository, published: false)])
expect(letter.published).to be(true)
get letter_url(letter), as: :json
expect(json[:repositories]).to be_nil
end

it 'renders unpublished when requested from beckettapi' do
letter = create(:letter)
letter = create(:letter, letter_publisher: nil)
expect(letter.published).to be(false)
get(letter_url(letter), headers: { HTTP_REFERER: 'beckettapi.ecdsdev.org' })
expect(response).to be_successful
end

it 'return 404 when unpublished and not requested from beckettapi' do
letter = create(:letter)
letter = create(:letter, letter_publisher: nil)
expect(letter.published).to be(false)
get letter_url(letter)
# The recommendation causes the test to fail.
Expand Down