source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20180322134606_drop_indexes_created_without_migration.rb | Ruby | mit | 19 | main | 520 | class DropIndexesCreatedWithoutMigration < ActiveRecord::Migration[5.1]
def up
if index_exists?(:dimensions_items, %i[latest content_id], name: "idx_latest_content_id")
remove_index :dimensions_items, name: "idx_latest_content_id"
end
if index_exists?(:facts_metrics, %i[dimensions_date_id dimension... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20180309120223_add_primary_org_fields_to_dimensions_item.rb | Ruby | mit | 19 | main | 319 | class AddPrimaryOrgFieldsToDimensionsItem < ActiveRecord::Migration[5.1]
def change
add_column :dimensions_items, :primary_organisation_title, :string
add_column :dimensions_items, :primary_organisation_content_id, :string
add_column :dimensions_items, :primary_organisation_withdrawn, :boolean
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20181107170246_add_index_to_last_twelve_months_aggregations.rb | Ruby | mit | 19 | main | 244 | class AddIndexToLastTwelveMonthsAggregations < ActiveRecord::Migration[5.2]
def change
add_index :aggregations_search_last_twelve_months, %w(dimensions_edition_id upviews), name: "index_on_last_twelve_months_edition_id_upviews"
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20181106114625_create_aggregations_search_last_months.rb | Ruby | mit | 19 | main | 207 | class CreateAggregationsSearchLastMonths < ActiveRecord::Migration[5.2]
def change
Aggregations::MaterializedView.prepare
create_view :aggregations_search_last_months, materialized: true
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20181126135420_update_aggregations_search_last_six_months_to_version_2.rb | Ruby | mit | 19 | main | 215 | class UpdateAggregationsSearchLastSixMonthsToVersion2 < ActiveRecord::Migration[5.2]
def change
update_view :aggregations_search_last_six_months, version: 2, revert_to_version: 1, materialized: true
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20190402143148_rename_latest_column_to_live.rb | Ruby | mit | 19 | main | 209 | class RenameLatestColumnToLive < ActiveRecord::Migration[5.2]
def up
rename_column :dimensions_editions, :latest, :live
end
def down
rename_column :dimensions_editions, :live, :latest
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20181206115804_update_aggregations_search_last_six_months_to_version_3.rb | Ruby | mit | 19 | main | 215 | class UpdateAggregationsSearchLastSixMonthsToVersion3 < ActiveRecord::Migration[5.2]
def change
update_view :aggregations_search_last_six_months, version: 3, revert_to_version: 2, materialized: true
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20190603145810_update_aggregations_search_last_months_to_version_8.rb | Ruby | mit | 19 | main | 240 | class UpdateAggregationsSearchLastMonthsToVersion8 < ActiveRecord::Migration[5.2]
def change
update_view(
:aggregations_search_last_months,
version: 8,
revert_to_version: 7,
materialized: true,
)
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20180307113805_rename_column_dimensions_items_content_purpose_supertype.rb | Ruby | mit | 19 | main | 212 | class RenameColumnDimensionsItemsContentPurposeSupertype < ActiveRecord::Migration[5.1]
def change
rename_column :dimensions_items, :content_purpose_supertype, :content_purpose_document_supertype
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20190603111746_restore_organisation_related_view_indexes.rb | Ruby | mit | 19 | main | 663 | class RestoreOrganisationRelatedViewIndexes < ActiveRecord::Migration[5.2]
PERIODS = %w[
last_thirty_days
last_months
last_three_months
last_six_months
last_twelve_months
].freeze
def up
fields = %i[primary_organisation_id upviews warehouse_item_id]
PERIODS.each do |period|
add... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20190213155920_add_indexes_view_aggregations_search_last_three_months.rb | Ruby | mit | 19 | main | 1,399 | class AddIndexesViewAggregationsSearchLastThreeMonths < ActiveRecord::Migration[5.2]
def up
execute "create index aggregations_search_last_three_months_gin_base_path on aggregations_search_last_three_months using gin(to_tsvector('english'::regconfig, replace((base_path)::text, '/'::text, ' '::text)))"
execute... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20170518121026_create_audits.rb | Ruby | mit | 19 | main | 284 | class CreateAudits < ActiveRecord::Migration[5.0]
def change
create_table :audits do |t|
t.string :content_id, null: false
t.string :uid, null: false
t.timestamps
end
add_index :audits, :content_id, unique: true
add_index :audits, :uid
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20190312141423_update_aggregations_search_last_six_months_to_version_8.rb | Ruby | mit | 19 | main | 263 | class UpdateAggregationsSearchLastSixMonthsToVersion8 < ActiveRecord::Migration[5.2]
def change
update_view :aggregations_search_last_six_months,
version: 8,
revert_to_version: 7,
materialized: true
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20181107165733_add_index_to_last_six_months_aggregations.rb | Ruby | mit | 19 | main | 235 | class AddIndexToLastSixMonthsAggregations < ActiveRecord::Migration[5.2]
def change
add_index :aggregations_search_last_six_months, %w(dimensions_edition_id upviews), name: "index_on_last_six_months_edition_id_upviews"
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20180926091756_add_default_value_to_feedback_metrics.rb | Ruby | mit | 19 | main | 972 | class AddDefaultValueToFeedbackMetrics < ActiveRecord::Migration[5.2]
class MigrationMetric < ActiveRecord::Base
self.table_name = :facts_metrics
end
def up
say "Updating nil values in `is_this_useful_yes` column in `facts_metrics`"
MigrationMetric.where(is_this_useful_yes: nil).update_all(is_this_use... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20180921122451_add_index_dimensions_items_content_uuid.rb | Ruby | mit | 19 | main | 296 | class AddIndexDimensionsItemsContentUuid < ActiveRecord::Migration[5.2]
def change
add_index :dimensions_items, :content_uuid, name: "index_dimensions_items_content_uuid"
add_index :dimensions_items, %i[content_uuid latest], name: "index_dimensions_items_content_uuid_latest"
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20181031112754_create_dimensions_months.rb | Ruby | mit | 19 | main | 449 | class CreateDimensionsMonths < ActiveRecord::Migration[5.2]
def change
create_table :dimensions_months, id: false do |t|
t.string :id, null: false
t.string :month_name, null: false
t.string :month_name_abbreviated, null: false
t.integer :month_number, null: false
t.integer :quarter, ... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20181025133812_remove_duplicated_warehouse_item_ids_in_metrics.rb | Ruby | mit | 19 | main | 872 | class RemoveDuplicatedWarehouseItemIdsInMetrics < ActiveRecord::Migration[5.2]
def up
loop do
say "------> Deleting batch of duplications"
total = clean_up_duplicated_metrics!
break if total.zero?
end
end
private
def clean_up_duplicated_metrics!
edition_ids = Dimensions::Edition.
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20181211115944_update_aggregations_search_last_six_months_to_version_4.rb | Ruby | mit | 19 | main | 263 | class UpdateAggregationsSearchLastSixMonthsToVersion4 < ActiveRecord::Migration[5.2]
def change
update_view :aggregations_search_last_six_months,
version: 4,
revert_to_version: 3,
materialized: true
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20180610080335_add_unique_index_to_facts_metrics.rb | Ruby | mit | 19 | main | 364 | class AddUniqueIndexToFactsMetrics < ActiveRecord::Migration[5.1]
def change
remove_index :facts_metrics, name: "index_facts_metrics_date_item_id"
remove_index :facts_metrics, name: "index_facts_metrics_on_dimensions_item_id"
add_index :facts_metrics, %i[dimensions_date_id dimensions_item_id], name: :metr... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20171228132858_create_dimensions_items.rb | Ruby | mit | 19 | main | 304 | class CreateDimensionsItems < ActiveRecord::Migration[5.1]
def change
create_table :dimensions_items do |t|
t.string :content_id
t.string :title
t.string :link
t.string :description
t.string :organisation_id
t.text :content
t.timestamps
end
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20181122142744_remove_default_zeros_from_events_gas.rb | Ruby | mit | 19 | main | 373 | class RemoveDefaultZerosFromEventsGas < ActiveRecord::Migration[5.2]
COLS = %i[pviews upviews searches exits entrances bounces bounce_rate avg_page_time page_time].freeze
def up
COLS.each do |col|
change_column_default(:events_gas, col, nil)
end
end
def down
COLS.each do |col|
change_c... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | db/migrate/20190213155940_add_indexes_view_aggregations_search_last_twelve_months.rb | Ruby | mit | 19 | main | 1,418 | class AddIndexesViewAggregationsSearchLastTwelveMonths < ActiveRecord::Migration[5.2]
def up
execute "create index aggregations_search_last_twelve_months_gin_base_path on aggregations_search_last_twelve_months using gin(to_tsvector('english'::regconfig, replace((base_path)::text, '/'::text, ' '::text)))"
exec... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | lib/tasks/editions.rake | Ruby | mit | 19 | main | 2,535 | namespace :editions do
desc "Update withdrawn editions"
task set_withdrawn: :environment do
editions = Dimensions::Edition.all
puts "Updating #{editions.count} editions"
ActiveRecord::Base.transaction do
Dimensions::Edition.find_each(batch_size: 1000).each_with_index do |edition, index|
p... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | lib/tasks/data_migrations.rake | Ruby | mit | 19 | main | 819 | DATA_MIGRATION_BATCH_SIZE = 25_000
namespace :data_migrations do
desc "Sets all metrics with no useful yes/no responses to have null for satisfaction"
task :satisfaction_defaults_to_null, %i[from to] => [:environment] do |_t, args|
from = args[:from].to_date
to = args[:to].to_date
(from..to).each do |... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | lib/tasks/etl.rake | Ruby | mit | 19 | main | 4,187 | namespace :etl do
desc "Run ETL main process for yesterday"
task main: :environment do
unless Etl::Main::MainProcessor.process
abort("Etl::Main::MainProcessor failed")
end
end
desc "Run Etl::Aggregations::Monthly for range of dates"
task :repopulate_aggregations_month, %i[from to] => [:environm... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | lib/tasks/update_file_counts.rake | Ruby | mit | 19 | main | 1,076 | namespace :editions do
desc "Update file counts for editions"
task update_file_counts: :environment do
editions = Dimensions::Edition.all.live.includes(:facts_edition, :publishing_api_event)
edition_count = editions.count
batch_size = 100
total_batches = (edition_count.to_f / batch_size).ceil
p... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | lib/tasks/publishing_api_consumer.rake | Ruby | mit | 19 | main | 661 | namespace :publishing_api do
desc "Run worker to publishing API from rabbitmq"
task consumer: :environment do
GovukMessageQueueConsumer::Consumer.new(
queue_name: ENV["RABBITMQ_QUEUE"],
processor: Streams::Consumer.new,
).run
rescue SignalException
logger.info "SignalException suppressed"
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | config/application.rb | Ruby | mit | 19 | main | 1,573 | require_relative "boot"
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
# require "action_mailer/railtie"
# require "action_mailbox/engine"
# require "action... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | config/routes.rb | Ruby | mit | 19 | main | 1,620 | Rails.application.routes.draw do
root to: "items#index"
resources :items, only: %w[index show], param: :content_id
namespace :api, defaults: { format: :json } do
get "/v1/metrics/", to: "metrics#index"
get "/v1/healthcheck", to: "healthcheck#index"
get "/v1/organisations", to: "organisations#index"
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | config/initializers/govuk_date_formats.rb | Ruby | mit | 19 | main | 295 | # 1 January 2013
Date::DATE_FORMATS[:govuk_date] = "%-e %B %Y"
# 1 Jan 2013
Date::DATE_FORMATS[:govuk_date_short] = "%-e %b %Y"
# 1:15pm, 1 January 2013
Time::DATE_FORMATS[:govuk_date] = "%-I:%M%P, %-e %B %Y"
# 1:15pm, 1 Jan 2013
Time::DATE_FORMATS[:govuk_date_short] = "%-I:%M%P, %-e %b %Y" |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | config/initializers/inflections.rb | Ruby | mit | 19 | main | 330 | ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym "AAIB"
inflect.acronym "CMA"
inflect.acronym "DFID"
inflect.acronym "ESI"
inflect.acronym "FOI"
inflect.acronym "HMRC"
inflect.acronym "HTML"
inflect.acronym "MAIB"
inflect.acronym "RAIB"
inflect.acronym "UTAAC"
inflect.acronym... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | config/environments/development.rb | Ruby | mit | 19 | main | 2,789 | require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Make code changes take effect immediately without server restart.
config.enable_reloading = true
# Do not eager load code on boot.
config.eager... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | config/environments/test.rb | Ruby | mit | 19 | main | 2,134 | # The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
Rails.application.configure do
# Settings... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | config/environments/production.rb | Ruby | mit | 19 | main | 2,773 | require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.enable_reloading = false
# Eager load code on boot for better performance and memory savings (ignor... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/rails_helper.rb | Ruby | mit | 19 | main | 1,620 | # Must go at top of file
require "simplecov"
SimpleCov.start "rails"
ENV["RAILS_ENV"] ||= "test"
require File.expand_path("../config/environment", __dir__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require "rspec/rails"
require "support/authentication"
require "rake"
requ... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/finders/aggregations_spec.rb | Ruby | mit | 19 | main | 3,011 | RSpec.describe Finders::Aggregations do
it "has aggregations for all metric names" do
result = Finders::Aggregations.new.run
expect(result.keys).to eq(Metric.find_all_names.map(&:to_sym))
end
it "return aggregated values for daily metrics" do
edition = create :edition, base_path: "/path/1", date: "20... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/finders/all_document_types_spec.rb | Ruby | mit | 19 | main | 1,629 | RSpec.describe Finders::AllDocumentTypes do
subject { described_class }
describe ".find_all" do
it "returns a list of document types" do
create(:edition, document_type: "news_story")
create(:edition, document_type: "guide")
expect(subject.run).to all(be_a(DocumentType))
end
it "filt... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/finders/select_view_spec.rb | Ruby | mit | 19 | main | 1,460 | RSpec.describe Finders::SelectView do
let(:primary_org_id) { "96cad973-92dc-41ea-a0ff-c377908fee74" }
describe "#select_view" do
it "returns last 30 days view if date range is `past-30-days`" do
expect(described_class.new("past-30-days").run).to eq(model_name: Aggregations::SearchLastThirtyDays, table_na... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/finders/document_children_spec.rb | Ruby | mit | 19 | main | 10,013 | RSpec.describe Finders::DocumentChildren do
include AggregationsSupport
let(:time_period) { "past-30-days" }
let(:sort_key) { nil }
let(:sort_direction) { nil }
let(:filters) do
{
time_period:,
sort_key:,
sort_direction:,
}
end
subject { described_class }
before do
creat... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/finders/content_spec.rb | Ruby | mit | 19 | main | 21,271 | RSpec.describe Finders::Content do
include AggregationsSupport
let(:primary_org_id) { "96cad973-92dc-41ea-a0ff-c377908fee74" }
let(:filter) do
{
date_range: "past-30-days",
organisation_id: primary_org_id,
document_type: nil,
sort_attribute: nil,
sort_direction: nil,
}
en... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/finders/find_series_spec.rb | Ruby | mit | 19 | main | 2,724 | RSpec.describe Finders::FindSeries do
context "all" do
it "returns a series of all metrics" do
create :metric, date: Time.zone.today, pviews: 1
expect(described_class.new.run.length).to eq(14)
end
end
context "between" do
it "returns metrics for a given date range" do
edition = cre... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/finders/all_organisations_spec.rb | Ruby | mit | 19 | main | 1,506 | RSpec.describe Finders::AllOrganisations do
subject { described_class }
describe ".find_all" do
context "sorting" do
before do
create(:edition, document_type: "organisation", title: "Organisation C")
create(:edition, document_type: "organisation", title: "Organisation A")
create(:... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/finders/series_spec.rb | Ruby | mit | 19 | main | 934 | RSpec.describe Finders::Series do
let!(:day1) { Date.new(2018, 1, 13) }
let!(:day2) { Date.new(2018, 1, 14) }
let!(:day3) { Date.new(2018, 1, 15) }
let!(:content_id) { SecureRandom.uuid }
let!(:base_path) { "/base_path" }
let!(:edition) { create :edition, date: day1, content_id:, base_path:, locale: "en" }
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/monitor/facts_spec.rb | Ruby | mit | 19 | main | 1,663 | RSpec.describe Monitor::Facts do
around do |example|
Timecop.freeze(Date.new(2018, 1, 15)) { example.run }
end
let(:yesterday) { "2018-01-14" }
before { allow(GovukStatsd).to receive(:count) }
it "sends StatsD counter for facts metrics" do
expect(GovukStatsd).to receive(:count).with("monitor.facts.... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/monitor/aggregations_spec.rb | Ruby | mit | 19 | main | 767 | RSpec.describe Monitor::Aggregations do
around do |example|
Timecop.freeze(Date.new(2018, 3, 15)) { example.run }
end
let(:yesterday) { "2018-03-14" }
before { allow(GovukStatsd).to receive(:count) }
it "sends StatsD counter for all the aggregations" do
expect(GovukStatsd).to receive(:count).with("... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/monitor/messages_spec.rb | Ruby | mit | 19 | main | 1,244 | RSpec.describe Monitor::Messages do
before do
allow(GovukStatsd).to receive(:increment)
end
it "increments major if routing key ends .major" do
expect(GovukStatsd).to receive(:increment).with("monitor.messages.major")
Monitor::Messages.run("news_story.major")
end
it "increments minor if routing ... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/monitor/dimensions_spec.rb | Ruby | mit | 19 | main | 1,443 | RSpec.describe Monitor::Dimensions do
around do |example|
Timecop.freeze(Date.new(2018, 1, 15)) { example.run }
end
let(:yesterday) { "2018-01-14" }
before { allow(GovukStatsd).to receive(:count) }
it "sends StatsD counter of base_paths" do
expect(GovukStatsd).to receive(:count).with("monitor.dimen... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/monitor/etl_spec.rb | Ruby | mit | 19 | main | 1,006 | RSpec.describe Monitor::Etl do
around do |example|
Timecop.freeze(Date.new(2018, 1, 15)) { example.run }
end
let(:yesterday) { "2018-01-14" }
before { allow(GovukStatsd).to receive(:count) }
Metric.daily_metrics.map(&:name).each do |metric_name|
it "sends StatsD counter for daily metric: `#{metric_... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/aggregations/search_spec.rb | Ruby | mit | 19 | main | 1,242 | RSpec.describe Etl::Aggregations::Search do
subject { described_class }
before do
allow(Aggregations::SearchLastThirtyDays).to receive(:refresh)
allow(Aggregations::SearchLastMonth).to receive(:refresh)
allow(Aggregations::SearchLastThreeMonths).to receive(:refresh)
allow(Aggregations::SearchLastSi... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/aggregations/monthly_spec.rb | Ruby | mit | 19 | main | 4,011 | RSpec.describe Etl::Aggregations::Monthly do
subject { described_class }
let(:date) { Date.new(2018, 2, 20) }
let(:edition1) { create :edition, base_path: "/path1", live: true, date: "2018-02-20" }
let(:edition2) { create :edition, base_path: "/path2", live: true, date: "2018-02-20" }
it "calculates monthl... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/metadata/file_counter_spec.rb | Ruby | mit | 19 | main | 6,399 | require "gds_api/test_helpers/content_store"
module Performance
RSpec.describe Etl::Edition::Metadata::FileCounter do
include GdsApi::TestHelpers::ContentStore
shared_examples "document file counter" do |counter_method:, matching_extensions:, non_matching:, no_dot:, near_miss:|
%w[documents body].each... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/transaction_spec.rb | Ruby | mit | 19 | main | 584 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns content json if schema_name is 'transaction'" do
json = { schema_name: "transaction",
details: { introductory_paragraph: "Report changes",
start_button_text: "Start",
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/no_content_spec.rb | Ruby | mit | 19 | main | 1,756 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
before do
allow(GovukError).to receive(:notify)
end
it "handles schemas that does not have useful content" do
no_content_schemas = %w[
coming_soon
completed_transaction
content_block
content_block_conta... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/generic_with_links_spec.rb | Ruby | mit | 19 | main | 711 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns nil if json does not have 'external_related_links' key" do
json = { schema_name: "generic_with_external_related_links",
details: {} }
expect(subject.extract_content(json.deep_stringify_keys)).to eq(nil)
e... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/service_manual_homepage_spec.rb | Ruby | mit | 19 | main | 715 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns content json if schema_name is 'service_manual_homepage'" do
json = { schema_name: "service_manual_homepage",
title: "Service Manual",
description: "Digital Service Standard",
links: {... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/statistics_announcement_spec.rb | Ruby | mit | 19 | main | 445 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns content json if schema_name is 'statistics_announcement'" do
json = { schema_name: "statistics_announcement",
description: "Announcement",
details: { display_date: "25 December 2017", state: "close... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/service_manual_topic_spec.rb | Ruby | mit | 19 | main | 775 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns description if json does not have 'groups' key" do
json = { schema_name: "service_manual_topic",
description: "Blogs",
details: {} }
expect(subject.extract_content(json.deep_stringify_keys)).to... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/reading_time_spec.rb | Ruby | mit | 19 | main | 427 | RSpec.describe Etl::Edition::Content::ReadingTime do
subject { described_class }
describe "#calculate" do
it "calculate readability based on 200 words per minute" do
expected_reading_time = 400 / 200
expect(subject.calculate(400)).to eq(expected_reading_time)
end
it "rounds up to 1 readin... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/local_transaction_spec.rb | Ruby | mit | 19 | main | 462 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns content json if schema_name is 'local_transaction'" do
json = { schema_name: "local_transaction",
details: { introduction: "Greetings",
need_to_know: "A Name",
mo... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/parser_spec.rb | Ruby | mit | 19 | main | 2,391 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
describe "#extract_content" do
context "when valid schema" do
describe "extraction fails with a StandardError" do
it "logs the error with Sentry" do
json = { schema_name: "place",
details: { i... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/step_by_step_spec.rb | Ruby | mit | 19 | main | 891 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns content json if schema_name is 'step_by_step_nav'" do
json = { schema_name: "step_by_step_nav",
details: { step_by_step_nav: {
title: "Learn to drive a car: step by step",
introduc... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/taxon_spec.rb | Ruby | mit | 19 | main | 730 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns description if json does not have any child_taxons" do
json = { schema_name: "taxon",
description: "Blogs",
links: {} }
expect(subject.extract_content(json.deep_stringify_keys)).to eq("Blogs")
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/finder_spec.rb | Ruby | mit | 19 | main | 593 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns content json if schema_name is 'finder'" do
json = { schema_name: "finder",
title: "Contact HMRC",
links: { children: [
{ title: "Personal Tax", description: "Email, write or phone u... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/place_spec.rb | Ruby | mit | 19 | main | 402 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns content json if schema is 'place'" do
json = { schema_name: "place",
details: { introduction: "Introduction",
more_information: "Enter your postcode" } }
expect(subject.extract_conte... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/travel_advice_index_spec.rb | Ruby | mit | 19 | main | 620 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns nil if json does not have children array" do
json = { schema_name: "travel_advice_index",
links: {} }
expect(subject.extract_content(json.deep_stringify_keys)).to eq(nil)
end
it "returns content json" ... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/unpublished_spec.rb | Ruby | mit | 19 | main | 606 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns content json if schema_name is 'gone'" do
json = { schema_name: "gone",
details: { explanation: "No page here" } }
expect(subject.extract_content(json.deep_stringify_keys)).to eq("No page here")
end
it... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/hmrc_manual_spec.rb | Ruby | mit | 19 | main | 992 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns content json if schema_name is 'hmrc_manual'" do
json = { schema_name: "hmrc_manual",
title: "HMRC Manual",
description: "Manual of items",
details: {
child_section_grou... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/mainstream_spec.rb | Ruby | mit | 19 | main | 772 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns content json if schema_name is 'mainstream_browse_page'" do
json = { schema_name: "mainstream_browse_page",
title: "Travel Abroad",
description: "Go abroad",
links: { children: [
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/body_content_spec.rb | Ruby | mit | 19 | main | 3,187 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
let(:valid_types) do
%w[
answer
calendar
call_for_evidence
case_study
consultation
corporate_information_page
detailed_guide
document_collection
fatality_notice
get_involved
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/finder_email_signup_spec.rb | Ruby | mit | 19 | main | 805 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
describe "FinderEmailSignup" do
it "returns description if json does not have 'email_signup_choice' key" do
json = { schema_name: "finder_email_signup",
description: "Use buttons",
details: {} }
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/email_alert_signup_spec.rb | Ruby | mit | 19 | main | 714 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
describe "EmailAlertSignup" do
it "returns summary if json does not have 'breadcrumbs' key" do
json = { schema_name: "email_alert_signup",
details: { summary: "Summary" } }
expect(subject.extract_content(json... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/service_manual_service_toolkit_spec.rb | Ruby | mit | 19 | main | 1,317 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns nil if json does not have 'collection' key" do
json = {
schema_name: "service_manual_service_toolkit",
details: {},
}
expect(subject.extract_content(json.deep_stringify_keys)).to eq(nil)
end
it "ret... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/service_manual_standard_spec.rb | Ruby | mit | 19 | main | 940 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns title and body if json does not have 'children' key" do
json = {
schema_name: "service_manual_service_standard",
title: "sm title",
details: { body: "the main body" },
links: {},
}
expect(sub... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/licence_spec.rb | Ruby | mit | 19 | main | 1,293 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns content json if schema is 'licence'" do
json = { schema_name: "licence",
details: { licence_overview: "licence expired" } }
expect(subject.extract_content(json.deep_stringify_keys)).to eq("licence expired")... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/content_array_spec.rb | Ruby | mit | 19 | main | 811 | RSpec.describe Etl::Edition::Content::Parsers::ContentArray do
it "skips blank content" do
content = ""
result = described_class.new.parse(content)
expect(result).to be_nil
end
it "returns content provided as string" do
content = "Some string"
result = described_class.new.parse(content)
e... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/need_spec.rb | Ruby | mit | 19 | main | 397 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "returns content if schema name is 'need'" do
json = {
schema_name: "need",
details: {
role: "the role",
goal: "the goal",
benefit: "the benefit",
},
}
expect(subject.extract_content... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/edition/content/contact_spec.rb | Ruby | mit | 19 | main | 3,476 | RSpec.describe Etl::Edition::Content::Parser do
subject { described_class }
it "does not return phone numbers if there is no 'phone_numbers' key" do
json = {
schema_name: "contact",
details: {
description: "main desc",
email_addresses: [
{ title: "title 1", description: "<... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/ga/internal_search_processor_spec.rb | Ruby | mit | 19 | main | 5,246 | require "gds-api-adapters"
RSpec.describe Etl::GA::InternalSearchProcessor do
subject { described_class }
let(:date) { Date.new(2018, 2, 20) }
context "When the base_path matches the GA path" do
before { allow(Etl::GA::InternalSearchService).to receive(:find_in_batches).and_yield(ga_response) }
it "up... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/ga/user_feedback_processor_spec.rb | Ruby | mit | 19 | main | 4,424 | require "gds-api-adapters"
RSpec.describe Etl::GA::UserFeedbackProcessor do
subject { described_class }
let(:date) { Date.new(2018, 2, 20) }
context "When the base_path matches the GA path" do
before { allow(Etl::GA::UserFeedbackService).to receive(:find_in_batches).and_yield(ga_response) }
it "update... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/ga/bigquery_spec.rb | Ruby | mit | 19 | main | 1,503 | RSpec.describe Etl::GA::Bigquery do
describe "Connecting to the Google Cloud BigQuery API" do
before do
stub_request(:post, "https://www.googleapis.com/oauth2/v4/token")
.to_return(status: 200, body: "{}", headers: { "Content-Type" => "application/json" })
ENV["BIGQUERY_PROJECT"] = "bigquery-pr... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/ga/user_feedback_service_spec.rb | Ruby | mit | 19 | main | 1,907 | RSpec.describe Etl::GA::UserFeedbackService do
subject { Etl::GA::UserFeedbackService }
let(:google_client) { instance_double(Google::Cloud::Bigquery::Project) }
let(:results) { instance_double(Google::Cloud::Bigquery::Data) }
before do
allow(Etl::GA::Bigquery).to receive(:build).and_return(google_client)... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/ga/internal_search_service_spec.rb | Ruby | mit | 19 | main | 1,934 | RSpec.describe Etl::GA::InternalSearchService do
subject { Etl::GA::InternalSearchService }
let(:google_client) { instance_double(Google::Cloud::Bigquery::Project) }
let(:results) { instance_double(Google::Cloud::Bigquery::Data) }
before do
allow(Etl::GA::Bigquery).to receive(:build).and_return(google_cli... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/ga/views_and_navigation_service_spec.rb | Ruby | mit | 19 | main | 3,522 | RSpec.describe Etl::GA::ViewsAndNavigationService do
subject { Etl::GA::ViewsAndNavigationService }
let(:google_client) { instance_double(Google::Cloud::Bigquery::Project) }
let(:results) { instance_double(Google::Cloud::Bigquery::Data) }
before do
allow(Etl::GA::Bigquery).to receive(:build).and_return(go... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/ga/views_and_navigation_processor_spec.rb | Ruby | mit | 19 | main | 4,985 | require "gds-api-adapters"
RSpec.describe Etl::GA::ViewsAndNavigationProcessor do
subject { described_class }
let!(:edition1) { create :edition, base_path: "/Path1", live: true, date: "2018-02-20" }
# We have some mixed case paths so we need them to match the lowercase ones in GA
let!(:edition2) { create :ed... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/ga/concerns/transform_path_spec.rb | Ruby | mit | 19 | main | 2,886 | class EtlSpecDummy
include Etl::GA::Concerns::TransformPath
include Traceable
end
RSpec.describe Etl::GA::Concerns::TransformPath do
it "events that have gov.uk prefix get formatted to remove prefix" do
create(:ga_event, page_path: "/https://www.gov.uk/topics", process_name: "views")
events_with_prefix =... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/feedex/processor_spec.rb | Ruby | mit | 19 | main | 4,038 | require "gds-api-adapters"
RSpec.describe Etl::Feedex::Processor do
let(:date) { Date.new(2018, 2, 20) }
let(:subject) { described_class }
context "When the base_path matches the feedex path" do
before { allow_any_instance_of(Etl::Feedex::Service).to receive(:find_in_batches).and_yield(feedex_response) }
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/feedex/service_spec.rb | Ruby | mit | 19 | main | 3,526 | RSpec.describe Etl::Feedex::Service do
let(:support_api) { double("support_api") }
let(:subject) { described_class.new(date, 20, support_api) }
describe "#find_in_batches" do
let(:date) { Date.new(2018, 2, 1) }
context "when there are no results" do
let(:response) { { "results" => [], "current_pag... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/main/main_processor_spec.rb | Ruby | mit | 19 | main | 5,186 | require "gds-api-adapters"
RSpec.describe Etl::Main::MainProcessor do
subject { described_class }
let(:date) { Date.new(2018, 2, 20) }
around do |example|
Timecop.freeze(date) { example.run }
end
before do
allow(Etl::GA::ViewsAndNavigationProcessor).to receive(:process).and_return(true)
allow(... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/etl/main/metrics_spec.rb | Ruby | mit | 19 | main | 975 | RSpec.describe Etl::Main::MetricsProcessor do
let(:date) { Date.new(2018, 3, 15) }
subject { described_class.new(date:) }
it "creates a Metrics fact per content item" do
create :edition, live: true
item = create(:edition, live: true, content_id: "cid1")
expect(subject.process).to be true
expec... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/api/document_children_request_spec.rb | Ruby | mit | 19 | main | 2,404 | RSpec.describe Api::DocumentChildrenRequest do
let(:params) { { time_period: "past-30-days" } }
describe "#to_filter" do
it "returns a hash with the parameters" do
request = described_class.new(time_period: "past-30-days", sort: "feedex:asc")
expect(request.to_filter).to eq(
time_period: "... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/api/content_request_spec.rb | Ruby | mit | 19 | main | 3,066 | RSpec.describe Api::ContentRequest do
let(:params) { { date_range: "past-30-days", organisation_id: "all" } }
describe "#to_filter" do
it "returns a hash with the parameters" do
request = Api::ContentRequest.new(
document_type: "guide",
organisation_id: "the-id",
search_term: "a t... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/streams/grow_dimension_spec.rb | Ruby | mit | 19 | main | 3,133 | RSpec.describe Streams::GrowDimension do
describe ".should_grow?" do
let(:edition) { create :edition, publishing_api_payload_version: 4 }
let(:new_attrs) do
{
document_text: "new text",
publishing_api_payload_version: "5",
}
end
subject { described_class }
it "returns ... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/streams/consumer_spec.rb | Ruby | mit | 19 | main | 582 | RSpec.describe Streams::Consumer do
subject { described_class.new }
it "increments `discard` in statsd when routing key is not valid" do
message = build(:message, routing_key: "invalid_routing_key")
expect(GovukStatsd).to receive(:increment).with("monitor.messages.discarded")
subject.process(message)
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/streams/message_processor_job_spec.rb | Ruby | mit | 19 | main | 314 | RSpec.describe Streams::MessageProcessorJob do
it "increments `monitor.messages.*` " do
message = build(:message, routing_key: "news_story.major")
expect(GovukStatsd).to receive(:increment).with("monitor.messages.major")
subject.perform(message.payload, message.delivery_info.routing_key)
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/streams/handlers/single_item_handler_spec.rb | Ruby | mit | 19 | main | 1,572 | RSpec.describe Streams::Handlers::SingleItemHandler do
let(:content_id) { SecureRandom.uuid }
let(:base_path) { "/base-path" }
let(:locale) { "en" }
let(:old_edition) do
create(
:edition,
content_id:,
base_path:,
locale: "en",
live: true,
)
end
subject { described_cla... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/streams/messages/single_item_message_spec.rb | Ruby | mit | 19 | main | 5,125 | RSpec.describe Streams::Messages::SingleItemMessage do
include PublishingEventProcessingSpecHelper
subject { described_class }
include_examples "BaseMessage#invalid?"
include_examples "BaseMessage#organisation_ids"
include_examples "BaseMessage#historically_political?"
include_examples "BaseMessage#withdr... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/streams/messages/multipart_message_spec.rb | Ruby | mit | 19 | main | 4,178 | RSpec.describe Streams::Messages::MultipartMessage do
include PublishingEventProcessingSpecHelper
subject { described_class }
include_examples "BaseMessage#invalid?"
include_examples "BaseMessage#organisation_ids"
include_examples "BaseMessage#historically_political?"
include_examples "BaseMessage#withdra... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/healthchecks/etl_metric_values_spec.rb | Ruby | mit | 19 | main | 959 | RSpec.describe Healthchecks::EtlMetricValues do
its(:name) { is_expected.to eq(:etl_metric_values_pviews) }
include_examples "Healthcheck enabled/disabled within time range"
subject { described_class.build(:pviews) }
let(:yesterday) { Date.yesterday }
context "when there are no pviews for yesterday" do
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/healthchecks/daily_metrics_check_spec.rb | Ruby | mit | 19 | main | 656 | RSpec.describe Healthchecks::DailyMetricsCheck do
include_examples "Healthcheck enabled/disabled within time range"
describe "#status" do
context "When there are metrics" do
before { create :metric, dimensions_date: Dimensions::Date.build(Date.yesterday) }
it "returns status :ok" do
expect... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.