Skip to content

Commit

Permalink
Add a way to try interesting objects in development and test
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Feb 14, 2024
1 parent 8523fc2 commit c7271f6
Show file tree
Hide file tree
Showing 24 changed files with 94,629 additions and 200 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ Start the rails app

## Getting data in development

Once you have Solr running you can load fixture data using `rake searchworks:fixtures`
Once you have Solr running you can load fixture data using `bin/rails searchworks:fixtures`
We have included fixture files in the `spec/fixtures/solr_documents` directory.

If you want to add other documents you can add the identifiers into `FixtureHarvester`. This will download more yml files to the fixture folder. Run `bin/rails searchworks:fixtures` again to reindex. Please submit your changes and the new yaml files via a pull request. Please use this judiciously as adding many fixtures may add unnecessary complexity and size to the codebase.

## "Logging in" as a User in development

Expand Down
33 changes: 33 additions & 0 deletions app/services/fixture_harvester.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Harvests some fixture data from production and stores it in yaml files.
# Usage:
# bin/rails runner "FixtureHarvester.harvest_all"
#
# You can then load the yaml into solr using `rake searchworks:fixtures'
class FixtureHarvester
FIXTURES = [
'5488000', # Bound with parent
'2279186', # Bound with (no Folio items) (TODO: merge with 20 or 23?)
'14136548', # Online resource (no Folio items)
'4085072', # A collection of images (TODO: merge with 24?)
'13553090', # A uniform title (dotdotdotdot)
'2472159' # one hrid for multiple purl images (TODO: merge with 8923346, 20, or 23?)
].freeze

def self.harvest_all
FIXTURES.each { |id| harvest(id) }
end

def self.harvest(id)
response = conn.get("#{id}.json")
yaml = response.body.dig('response', 'document').except('_version_').to_yaml
File.write("spec/fixtures/solr_documents/#{id}.yml", yaml)
end

def self.conn
Faraday.new 'https://searchworks.stanford.edu/view/' do |conn|
conn.response :json, content_type: /\bjson$/

conn.adapter Faraday.default_adapter
end
end
end
16 changes: 16 additions & 0 deletions lib/fixtures_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ class FixturesIndexer
include MarcMetadataFixtures
include ModsFixtures

# marc_json_struct and folio_json_struct are explicitly not included here
STRUCT_KEYS = [
"works_struct",
"author_struct",
"marc_links_struct",
"summary_struct",
"uniform_title_display_struct",
"holdings_json_struct",
"toc_struct",
"item_display_struct"
].freeze

def self.run
FixturesIndexer.new.run
end
Expand Down Expand Up @@ -41,6 +53,10 @@ def fixtures
rendered_template = fixture_template.result(binding)
data = YAML::load rendered_template
data[:item_display_struct] &&= data[:item_display_struct].map(&:to_json)
STRUCT_KEYS.each do |key|
data[key] &&= data[key].map(&:to_json)
end

data
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/access_points/government_documents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
expect(page).to have_css('.filter-value', text: 'Government document')
end

expect(total_results).to eq 2
expect(total_results).to eq 4
end
end
4 changes: 2 additions & 2 deletions spec/features/alternate_catalog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
wait_for_ajax
within '.alternate-catalog' do
expect(page).to have_css 'h3', text: 'Your search also found results in'
expect(page).to have_css 'a.btn', text: 'See 31 catalog results'
expect(page).to have_css 'a[href="/catalog?q=1%2A&f[format_main_ssim][]=Book"]', text: 'Book (10)'
expect(page).to have_css 'a.btn', text: 'See 37 catalog results'
expect(page).to have_css 'a[href="/catalog?q=1%2A&f[format_main_ssim][]=Book"]', text: 'Book (13)'
expect(page).to have_css 'a[href="/catalog?q=1%2A&f[format_main_ssim][]=Image"]', text: 'Image (7)'
expect(page).to have_css 'a[href="/catalog?q=1%2A&f[format_main_ssim][]=Database"]', text: 'Database (5)'
expect(page).to have_css 'a[href="/catalog?q=1%2A&f[format_main_ssim][]=Newspaper"]', text: 'Newspaper (4)'
Expand Down
2 changes: 1 addition & 1 deletion spec/features/rss_feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end
end

it 'sorts the new books feed by the data cataloged field' do
it 'sorts the new books feed by the date_cataloged field' do
within('.search_num_of_results') do
click_link 'RSS feed for this result'
end
Expand Down
Loading

0 comments on commit c7271f6

Please sign in to comment.