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 | spec/domain/healthchecks/monthly_aggregations_spec.rb | Ruby | mit | 19 | main | 744 | RSpec.describe Healthchecks::MonthlyAggregations do
include_examples "Healthcheck enabled/disabled within time range"
around do |example|
Timecop.freeze(Time.zone.local(2019, 2, 22, 14, 0)) { example.run }
end
its(:name) { is_expected.to eq(:aggregations) }
describe "#status" do
context "When there... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/domain/healthchecks/search_aggregations_spec.rb | Ruby | mit | 19 | main | 1,126 | RSpec.describe Healthchecks::SearchAggregations do
include AggregationsSupport
include_examples "Healthcheck enabled/disabled within time range"
let(:subject) { described_class.build(:last_month) }
its(:name) { is_expected.to eq(:search_last_month) }
describe "status" do
let!(:primary_org_id) { "96cad9... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/factories/messages.rb | Ruby | mit | 19 | main | 5,493 | require "govuk_message_queue_consumer/test_helpers/mock_message"
FactoryBot.define do
factory :message, class: GovukMessageQueueConsumer::MockMessage do
transient do
sequence(:payload_version) { |i| 10 + i }
schema_name { "detailed_guide" }
document_type { "detailed_guide" }
base_path { "... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/factories/metrics.rb | Ruby | mit | 19 | main | 314 | FactoryBot.define do
factory :metric, class: Facts::Metric do
dimensions_date { Dimensions::Date.find_existing_or_create(date.to_date) }
dimensions_edition { edition }
pviews { 10 }
upviews { 5 }
transient do
date { Time.zone.today }
edition { create :edition }
end
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/factories/user.rb | Ruby | mit | 19 | main | 306 | FactoryBot.define do
factory :user do
transient do
organisation { nil }
end
sequence(:uid) { |i| "user-#{i}" }
sequence(:name) { |i| "Test User #{i}" }
email { "user@example.com" }
permissions { %w[signin] }
organisation_slug { "government-digital-service" }
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/factories/editions.rb | Ruby | mit | 19 | main | 1,608 | FactoryBot.define do
factory :edition, class: Dimensions::Edition do
live { true }
locale { "en" }
parent { nil }
sequence(:content_id) { SecureRandom.uuid }
sequence(:title) { |i| "title - #{i}" }
sequence(:base_path) { |i| "/base-path-#{i}" }
sequence(:description) { |i| "description - #... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/factories/dimensions_date.rb | Ruby | mit | 19 | main | 213 | FactoryBot.define do
factory :dimensions_date, class: Dimensions::Date do
sequence(:date) { |i| i.days.ago.to_date }
initialize_with { Dimensions::Date.find_existing_or_create(date.to_date) }
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/factories/monthly_metrics.rb | Ruby | mit | 19 | main | 620 | FactoryBot.define do
factory :monthly_metric, class: "Aggregations::MonthlyMetric" do
transient do
month { Dimensions::Month.build(Time.zone.today).id }
edition { create :edition }
end
dimensions_month do
y, m = *month.split("-").map(&:to_i)
Dimensions::Month.find_existing_or_cre... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/factories/ga_events.rb | Ruby | mit | 19 | main | 491 | FactoryBot.define do
factory :ga_event, class: Events::GA do
trait :with_views do
pviews { 10 }
upviews { 5 }
process_name { "views" }
end
trait :with_user_feedback do
useful_yes { 3 }
useful_no { 6 }
process_name { "user_feedback" }
end
trait :with_searches d... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/factories/facts_editions.rb | Ruby | mit | 19 | main | 239 | FactoryBot.define do
factory :facts_edition, class: Facts::Edition do
dimensions_date
pdf_count { 0 }
doc_count { 0 }
sentences { 0 }
words { 0 }
chars { 0 }
readability { 0 }
reading_time { 0 }
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/tasks/etl_spec.rb | Ruby | mit | 19 | main | 5,675 | RSpec.describe "etl.rake", type: task do
before do
allow($stdout).to receive(:puts)
end
describe "rake etl:main"
it "calls Etl::Main::MainProcessor.process" do
processor = class_double(Etl::Main::MainProcessor, process: true).as_stubbed_const
expect(processor).to receive(:process)
Rake::Task[... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/tasks/editions_spec.rb | Ruby | mit | 19 | main | 4,956 | RSpec.describe "rake editions:*", type: task do
describe "update_existing" do
it "updates edition when payload changes" do
payload = build(:message).payload
Streams::MessageProcessorJob.perform_now(payload, "something.major")
edition = Dimensions::Edition.first
edition.publishing_api_even... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/tasks/publishing_api_spec.rb | Ruby | mit | 19 | main | 887 | RSpec.describe "rake publishing_api:*", type: task do
let(:consumer) { double("message_consumer", run: nil) }
before(:all) do
ENV["RABBITMQ_QUEUE"] = "content_data_api"
ENV["RABBITMQ_QUEUE_BULK"] = "content_data_api_govuk_importer"
end
it "starts listener for PublishingAPI events" do
expect(GovukM... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/models/metric_spec.rb | Ruby | mit | 19 | main | 1,310 | EDITION_METRICS =
%w[
pdf_count
doc_count
readability
sentences
chars
words
reading_time
].freeze
DAILY_METRICS =
%w[
feedex
useful_no
useful_yes
searches
pviews
upviews
].freeze
RSpec.describe Metric do
describe ".find_all" do
it "returns a list of al... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/models/facts/edition_spec.rb | Ruby | mit | 19 | main | 814 | RSpec.describe Facts::Edition do
let(:edition) { create :edition, facts: quality_metrics }
let(:new_dimensions_edition) { create :edition }
let(:new_date) { create :dimensions_date }
let(:quality_metrics) do
{
pdf_count: 1,
doc_count: 1,
readability: 97,
chars: 21,
sentences: 1... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/models/facts/metric_spec.rb | Ruby | mit | 19 | main | 1,032 | RSpec.describe Facts::Metric, type: :model do
it { is_expected.to validate_presence_of(:dimensions_date) }
it { is_expected.to validate_presence_of(:dimensions_edition) }
describe ".for_yesterday" do
around do |example|
Timecop.freeze(Date.new(2018, 1, 15)) { example.run }
end
it "returns yest... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/models/dimensions/date_spec.rb | Ruby | mit | 19 | main | 6,063 | RSpec.describe Dimensions::Date, type: :model do
let(:date) { ::Date.new(2017, 12, 21) }
it { is_expected.to validate_presence_of(:date) }
it { is_expected.to validate_presence_of(:date_name) }
it { is_expected.to validate_presence_of(:date_name_abbreviated) }
it { is_expected.to validate_presence_of(:year)... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/models/dimensions/month_spec.rb | Ruby | mit | 19 | main | 2,673 | require "rails_helper"
RSpec.describe Dimensions::Month, type: :model do
it { is_expected.to validate_presence_of(:month_number) }
it { is_expected.to validate_numericality_of(:month_number).only_integer }
it { is_expected.to validate_inclusion_of(:month_number).in_range(1..12) }
it { is_expected.to validate_... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/models/dimensions/edition_spec.rb | Ruby | mit | 19 | main | 8,815 | RSpec.describe Dimensions::Edition, type: :model do
let(:now) { Time.utc(2018, 2, 21, 12, 31, 2) }
it { is_expected.to validate_presence_of(:content_id) }
it { is_expected.to validate_presence_of(:base_path) }
it { is_expected.to validate_presence_of(:publishing_api_payload_version) }
it { is_expected.to val... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/models/aggregations/search_last_six_months_spec.rb | Ruby | mit | 19 | main | 3,096 | RSpec.describe Aggregations::SearchLastSixMonths, type: :model do
include AggregationsSupport
subject { described_class }
it_behaves_like "a materialized view", described_class.table_name
include_examples "calculates satisfaction", Date.yesterday
include_examples "includes edition attributes", Date.yesterda... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/models/aggregations/search_aggregations_spec.rb | Ruby | mit | 19 | main | 2,704 | RSpec.describe Aggregations::SearchLastMonth, type: :model do
include AggregationsSupport
subject { described_class }
it_behaves_like "a materialized view", described_class.table_name
include_examples "calculates satisfaction", Time.zone.today.last_month.end_of_month
include_examples "includes edition attri... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/models/aggregations/monthly_metric_spec.rb | Ruby | mit | 19 | main | 218 | require "rails_helper"
RSpec.describe Aggregations::MonthlyMetric, type: :model do
it { is_expected.to validate_presence_of(:dimensions_month) }
it { is_expected.to validate_presence_of(:dimensions_edition) }
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/models/aggregations/search_last_thirty_days_spec.rb | Ruby | mit | 19 | main | 2,782 | RSpec.describe Aggregations::SearchLastThirtyDays, type: :model do
include AggregationsSupport
subject { described_class }
it_behaves_like "a materialized view", described_class.table_name
include_examples "calculates satisfaction", Date.yesterday
include_examples "includes edition attributes", Date.yesterd... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/models/aggregations/search_last_twelve_months_spec.rb | Ruby | mit | 19 | main | 3,118 | RSpec.describe Aggregations::SearchLastTwelveMonths, type: :model do
include AggregationsSupport
subject { described_class }
it_behaves_like "a materialized view", described_class.table_name
include_examples "calculates satisfaction", Date.yesterday
include_examples "includes edition attributes", Date.yeste... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/models/aggregations/search_last_three_months_spec.rb | Ruby | mit | 19 | main | 3,111 | RSpec.describe Aggregations::SearchLastThreeMonths, type: :model do
include AggregationsSupport
subject { described_class }
it_behaves_like "a materialized view", described_class.table_name
include_examples "calculates satisfaction", Date.yesterday
include_examples "includes edition attributes", Date.yester... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/requests/healthcheck_metrics_spec.rb | Ruby | mit | 19 | main | 563 | RSpec.describe "/healthcheck/metrics" do
before do
get "/healthcheck/metrics"
end
it "returns distinct organisations ordered by title" do
json = JSON.parse(response.body)
expect(json["checks"]).to include("daily_metrics")
.and(include("etl_metric_values_pviews"))
.and(include("etl_metric_val... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/requests/organisations_spec.rb | Ruby | mit | 19 | main | 838 | RSpec.describe "/organisations" do
before do
create :user
end
it "returns distinct organisations ordered by title" do
create :edition, document_type: "organisation", content_id: "org-1-id", title: "z Org"
create :edition, document_type: "organisation", content_id: "org-2-id", title: "a Org", acronym:... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/requests/document_types_spec.rb | Ruby | mit | 19 | main | 1,068 | RSpec.describe "/document_types" do
before do
create :user
end
it "returns distinct document types ordered by title" do
create :edition, document_type: "guide"
create :edition, document_type: "manual"
create :edition, document_type: "manual"
# the document types below should not appear in the... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/requests/healthcheck_search_spec.rb | Ruby | mit | 19 | main | 604 | RSpec.describe "/healthcheck/search" do
before do
get "/healthcheck/search"
end
it "returns distinct organisations ordered by title" do
json = JSON.parse(response.body)
expect(json["checks"]).to include("aggregations")
.and(include("search_last_month"))
.and(include("search_last_six_mont... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/requests/api/single_page_spec.rb | Ruby | mit | 19 | main | 8,904 | require "securerandom"
RSpec.describe "/single_page", type: :request do
let!(:base_path) { "/base_path" }
let!(:item) do
create :edition,
live: true,
title: "the title",
base_path:,
content_id: "the-content-id",
locale: "en",
document_type: "gui... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/requests/api/v1/content_spec.rb | Ruby | mit | 19 | main | 16,707 | RSpec.describe "/content" do
include AggregationsSupport
before { create :user }
let(:primary_organisation_id) { "e12e3c54-b544-4d94-ba1f-9846144374d2" }
describe "content item attributes" do
it "contains the expected metrics" do
edition1 = create :edition, date: 1.month.ago, primary_organisation_i... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/requests/api/v1/documents_spec.rb | Ruby | mit | 19 | main | 3,770 | RSpec.describe "/api/v1/documents/:document_id/children", type: :request do
include AggregationsSupport
before { create(:user) }
let(:content_id) { SecureRandom.uuid }
let(:locale) { "en" }
let(:time_period) { "past-30-days" }
describe "documents children" do
it "describes a documents with no children... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/requests/api/v1/metrics_spec.rb | Ruby | mit | 19 | main | 509 | RSpec.describe "/api/v1/metrics/", type: :request do
before { create(:user) }
include_examples "API response", "/api/v1/metrics"
describe "metrics index" do
it "describes the available metrics" do
get "/api/v1/metrics"
json = JSON.parse(response.body)
expect(json.count).to eq(::Metric.fi... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/requests/api/v1/healthcheck_spec.rb | Ruby | mit | 19 | main | 216 | RSpec.describe "/api/v1/healthcheck/", type: :request do
it "is not cacheable" do
get "/api/v1/healthcheck/"
expect(response.headers["Cache-Control"]).to eq "max-age=0, private, must-revalidate"
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/integration/item/extract_content_all_schemas_spec.rb | Ruby | mit | 19 | main | 469 | require "support/schemas_iterator"
RSpec.describe "Process parser", type: :integration do
include SchemasIterator
context "with a list of content schemas" do
SchemasIterator.each_schema do |schema_name, schema|
it "extracts the content for: #{schema_name}" do
payload = SchemasIterator.payload_fo... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/integration/item/import_edition_metrics_spec.rb | Ruby | mit | 19 | main | 1,812 | require "sidekiq/testing"
RSpec.describe "Import edition metrics" do
# FIXME: Rails 6 inconsistently overrides ActiveJob queue_adapter setting
# with TestAdapter #37270
# See https://github.com/rails/rails/issues/37270
around do |example|
perform_enqueued_jobs { example.run }
end
subject { Streams::Con... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/integration/streams/errors_spec.rb | Ruby | mit | 19 | main | 1,547 | require "sidekiq/testing"
require "govuk_message_queue_consumer/test_helpers"
require "gds_api/test_helpers/content_store"
RSpec.describe Streams::Consumer do
# FIXME: Rails 6 inconsistently overrides ActiveJob queue_adapter setting
# with TestAdapter #37270
# See https://github.com/rails/rails/issues/37270
ar... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/integration/streams/all_schemas_spec.rb | Ruby | mit | 19 | main | 771 | require "govuk_message_queue_consumer/test_helpers"
RSpec.describe "Process all schemas" do
let(:subject) { Streams::Consumer.new }
SchemasIterator.each_schema do |schema_name, schema|
it "has a parser for #{schema_name}" do
expect(Etl::Edition::Content::Parser.new.send(:for_schema, schema_name)).not_to... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/integration/streams/multiple/grow_dimension_spec.rb | Ruby | mit | 19 | main | 11,463 | require "govuk_message_queue_consumer/test_helpers/mock_message"
RSpec.describe "Process sub-pages for multipart content types" do
# FIXME: Rails 6 inconsistently overrides ActiveJob queue_adapter setting
# with TestAdapter #37270
# See https://github.com/rails/rails/issues/37270
around do |example|
perfor... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/integration/streams/multiple/parent_child_spec.rb | Ruby | mit | 19 | main | 5,506 | RSpec.describe "multi-part parent/child relationships" do
# FIXME: Rails 6 inconsistently overrides ActiveJob queue_adapter setting
# with TestAdapter #37270
# See https://github.com/rails/rails/issues/37270
around do |example|
perform_enqueued_jobs { example.run }
end
let(:content_id) { "8a5f749e-262c... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/integration/streams/parent_child/links_processor_spec.rb | Ruby | mit | 19 | main | 1,097 | RSpec.describe Streams::ParentChild::LinksProcessor do
let!(:parent) { create :edition, child_sort_order: ["child-1:en", "child-2:en"], warehouse_item_id: "parent:en" }
let!(:child_2) { create :edition, warehouse_item_id: "child-2:en" }
let!(:child_1) { create :edition, warehouse_item_id: "child-1:en" }
subjec... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/integration/streams/single/publishing_editions_spec.rb | Ruby | mit | 19 | main | 8,097 | require "govuk_message_queue_consumer/test_helpers"
def expect_messages_to_have_publishing_api_events(messages)
expected_messages = messages.map do |message|
have_attributes(
routing_key: message.delivery_info["routing_key"],
payload: message.payload,
)
end
expect(Events::PublishingApi.all).t... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/integration/streams/single/html_publication_parents_spec.rb | Ruby | mit | 19 | main | 3,026 | RSpec.describe "setting parents for html_publications" do
include ActiveJob::TestHelper
around do |example|
perform_enqueued_jobs { example.run }
end
let(:parent_message) do
build :message,
base_path: "/parent",
schema_name: "publication",
attributes: {
"docum... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/integration/streams/single/manuals_parent_child_spec.rb | Ruby | mit | 19 | main | 2,923 | RSpec.describe "setting parents for manuals" do
include ActiveJob::TestHelper
around do |example|
perform_enqueued_jobs { example.run }
end
let(:manual_message) do
build :message,
base_path: "/manual",
schema_name: "manual",
attributes: { "document_type" => "manual" }
e... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/integration/streams/single/grow_dimension_spec.rb | Ruby | mit | 19 | main | 3,484 | require "govuk_message_queue_consumer/test_helpers"
RSpec.describe Streams::Consumer do
# FIXME: Rails 6 inconsistently overrides ActiveJob queue_adapter setting
# with TestAdapter #37270
# See https://github.com/rails/rails/issues/37270
around do |example|
perform_enqueued_jobs { example.run }
end
in... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/integration/master/daily_metrics_spec.rb | Ruby | mit | 19 | main | 4,790 | RSpec.describe "Main process spec" do
let(:today) { Time.zone.today.to_s }
let(:yesterday) { Date.yesterday.to_s }
let!(:an_edition) { create :edition }
let!(:outdated_edition) { create :edition, content_id: "id1", base_path: "/path-1", live: false }
let!(:edition) { create :edition, content_id: "id1", base_... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/routing/documents_routing_spec.rb | Ruby | mit | 19 | main | 277 | RSpec.describe "documents endpoint routing" do
it "routes /documents/1234/children" do
expect(get: "api/v1/documents/1234/children").to route_to(
controller: "api/documents",
action: "children",
format: :json,
document_id: "1234",
)
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/routing/single_page_routing_spec.rb | Ruby | mit | 19 | main | 703 | RSpec.describe "single page endpoint routing" do
it "routes /single-item/very/long/base/path" do
expect(get: "/single_page/very/long/base/path").to route_to(
controller: "single_item",
action: "show",
format: :json,
base_path: "very/long/base/path",
)
end
it "routes /single_page (... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/support/publishing_event_processing_spec_helper.rb | Ruby | mit | 19 | main | 2,146 | module PublishingEventProcessingSpecHelper
def message_attributes(overrides = {})
{
"payload_version" => 7,
"locale" => "fr",
"title" => "the-title",
"document_type" => "detailed_guide",
"first_published_at" => "2018-04-19T12:00:40+01:00",
"public_updated_at" => "2018-04-20T12:... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/support/aggregations_support.rb | Ruby | mit | 19 | main | 612 | module AggregationsSupport
def recalculate_aggregations!
refresh_last_year_of_monthly_aggregations
refresh_views
end
private
def refresh_last_year_of_monthly_aggregations
Etl::Aggregations::Monthly.process(date: Time.zone.today)
13.times { |index| Etl::Aggregations::Monthly.process(date: index.... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/support/google_analytics_requests.rb | Ruby | mit | 19 | main | 444 | module GoogleAnalyticsRequests
def build_report_data(*report_rows)
Google::Apis::AnalyticsreportingV4::ReportData.new(rows: report_rows)
end
def build_report_row(dimensions:, metrics:)
Google::Apis::AnalyticsreportingV4::ReportRow.new(
dimensions:,
metrics: metrics.map do |metric|
Goo... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/support/schemas_iterator.rb | Ruby | mit | 19 | main | 482 | module SchemasIterator
def self.each_schema
all_schemas.each do |schema_name, value|
schema_name = schema_name.split("/")[-3]
yield schema_name, value
end
end
def self.payload_for(schema_name, schema)
all_payloads[schema_name] ||= GovukSchemas::RandomExample.new(schema:).payload
end
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/support/authentication.rb | Ruby | mit | 19 | main | 276 | module AuthenticationControllerHelpers
def login_as(user)
request.env["warden"] = double(
authenticate!: true,
authenticated?: true,
user:,
)
end
def stub_user
create(:user)
end
def login_as_stub_user
login_as stub_user
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/support/shared/shared_traps_and_logs.rb | Ruby | mit | 19 | main | 768 | RSpec.shared_examples "traps and logs errors in process" do |object, method|
let(:error) { StandardError.new }
before do
allow(GovukError).to receive(:notify)
allow(object).to receive(method).and_raise(error)
end
it "traps and logs the error to Sentry" do
expect(subject.process(date:)).to be false
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/support/shared/shared_api_response.rb | Ruby | mit | 19 | main | 874 | RSpec.shared_examples "API response" do |path, params = {}|
it "should be cacheable until the end of the day" do
Timecop.freeze(Time.zone.local(2020, 1, 1, 0, 0, 0)) do
get(path, params:)
expect(response.headers["ETag"]).to be_present
expect(response.headers["Cache-Control"]).to eq "max-age=360... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/support/shared/shared_messages.rb | Ruby | mit | 19 | main | 3,551 | RSpec.shared_examples "BaseMessage#historically_political?" do
describe "#historically_political?" do
let(:payload) { build(:message).payload }
let(:message) { described_class.new(payload, "routing_key") }
subject { message.historically_political? }
context "when payload has current goverment as fals... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/support/shared/shared_healthcheck_enabled.rb | Ruby | mit | 19 | main | 1,514 | RSpec.shared_examples "Healthcheck enabled/disabled within time range" do
around do |example|
@healthcheck_enabled = ENV["ETL_HEALTHCHECK_ENABLED"]
@healthcheck_hour = ENV["ETL_HEALTHCHECK_ENABLED_FROM_HOUR"]
example.run
ENV["ETL_HEALTHCHECK_ENABLED"] = @healthcheck_enabled
ENV["ETL_HEALTHCHECK_EN... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/support/shared/shared_aggregation_view.rb | Ruby | mit | 19 | main | 1,297 | RSpec.shared_examples "calculates satisfaction" do |date|
it "returns score with responses" do
edition1 = create :edition, base_path: "/path1", date: 2.months.ago
create :metric, edition: edition1, date:, useful_yes: 1, useful_no: 1
recalculate_aggregations!
expect(subject.first).to have_attributes(... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | spec/support/shared/shared_masterialized_views.rb | Ruby | mit | 19 | main | 464 | RSpec.shared_examples "a materialized view" do |table_name|
it "refresh the materialized view" do
expect(Scenic.database).to receive(:refresh_materialized_view).with(table_name, concurrently: true, cascade: false)
subject.refresh
end
it "prepares the environment to refresh the view" do
allow(Scenic.... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/specific_months.rb | Ruby | mit | 19 | main | 246 | module SpecificMonths
YEARS = (2018..Time.zone.today.year).to_a.freeze
MONTHS = Date::MONTHNAMES.compact.freeze
VALID_SPECIFIC_MONTHS = YEARS.flat_map do |year|
MONTHS.map do |month|
"#{month.downcase}-#{year}"
end
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/api/document_children_request.rb | Ruby | mit | 19 | main | 1,390 | class Api::DocumentChildrenRequest
VAILD_SORT_KEYS = (Metric.daily_metrics.map(&:name) + %w[title document_type sibling_order]).freeze
VALID_SORT_DIRECTIONS = %w[asc desc].freeze
VALID_TIME_PERIODS = SpecificMonths::VALID_SPECIFIC_MONTHS + ["past-30-days", "last-month", "past-3-months", "past-6-months", "past-yea... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/api/content_request.rb | Ruby | mit | 19 | main | 2,123 | class Api::ContentRequest
VAILD_SORT_ATTRIBUTES = (Metric.daily_metrics.map(&:name) + %w[title document_type]).freeze
VALID_SORT_DIRECTIONS = %w[asc desc].freeze
VALID_TIME_PERIODS = SpecificMonths::VALID_SPECIFIC_MONTHS + ["past-30-days", "last-month", "past-3-months", "past-6-months", "past-year"].freeze
incl... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/api/base_request.rb | Ruby | mit | 19 | main | 853 | class Api::BaseRequest
DATE_REGEX = /\A\d\d\d\d-\d\d-\d\d\Z/
private_constant :DATE_REGEX
include ActiveModel::Validations
attr_reader :from, :to
validates :from, presence: true, format: { with: DATE_REGEX, message: "Dates should use the format YYYY-MM-DD" }
validates :to, presence: true, format: { with... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/finders/series.rb | Ruby | mit | 19 | main | 500 | class Finders::Series
attr_reader :metric_name
def initialize(metric_name, all_metrics)
@metric_name = metric_name
@all_metrics = all_metrics
end
def total
time_series.reduce(0) { |total, time_point| total + time_point[:value] }
end
def time_series
time_series = @all_metrics.map do |metri... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/finders/find_series.rb | Ruby | mit | 19 | main | 918 | class Finders::FindSeries
def between(from:, to:)
@from = from
@to = to
self
end
def by_warehouse_item_id(warehouse_item_id)
@warehouse_item_id = warehouse_item_id
self
end
def editions
slice_editions
end
def run
dates = slice_dates
editions = slice_editions
metri... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/finders/select_view.rb | Ruby | mit | 19 | main | 1,398 | class Finders::SelectView
include SpecificMonths
attr_reader :date_range
def initialize(date_range)
@date_range = date_range
end
def run
return GovukError.notify(InvalidDateRangeError.new("Invalid date range: #{date_range}")) unless valid_date_range?
{ model_name:, table_name: }
end
private
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/finders/document_children.rb | Ruby | mit | 19 | main | 1,658 | class Finders::DocumentChildren
EDITION_COLUMNS = %w[base_path title primary_organisation_id document_type sibling_order].freeze
AGGREGATION_COLUMNS = %w[upviews pviews useful_yes useful_no satisfaction searches feedex].freeze
def self.call(*args)
new(*args).results
end
def results
filter_editions
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/finders/all_document_types.rb | Ruby | mit | 19 | main | 790 | class Finders::AllDocumentTypes
def self.run
new.run
end
def run
ActiveRecord::Base.connection
.execute(query)
.field_values("document_type")
.reject { |dt| DocumentType::IGNORED_TYPES.include? dt }
.map { |dt| DocumentType.new(id: dt, name: dt.humanize) }
end
private
def qu... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/finders/aggregations.rb | Ruby | mit | 19 | main | 1,375 | class Finders::Aggregations
def between(from:, to:)
@from = from
@to = to
self
end
def by_warehouse_item_id(warehouse_item_id)
@warehouse_item_id = warehouse_item_id
self
end
def run
dates = slice_dates
editions = slice_editions
metrics = Facts::Metric.all
metrics = me... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/finders/content.rb | Ruby | mit | 19 | main | 4,577 | class Finders::Content
include SpecificMonths
def self.call(filter:)
new(filter).call
end
def call
{
results: results.map(&method(:array_to_hash)),
page: @page,
total_pages: results.total_pages,
total_results:,
}
end
private
DEFAULT_PAGE_SIZE = 100
ALL = "all".freez... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/finders/all_organisations.rb | Ruby | mit | 19 | main | 547 | class Finders::AllOrganisations
def self.run(locale: "en")
new.run(locale)
end
def run(locale)
editions = find_all(locale)
editions.map { |edition| new_organisation(edition) }
end
private
def new_organisation(org)
Organisation.new(
id: org[:content_id],
name: org[:title],
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/monitor/facts.rb | Ruby | mit | 19 | main | 1,020 | class Monitor::Facts
include TraceAndRecoverable
def self.run(*args)
new(*args).run
end
def run
trap do
statsd_for_all_metrics!
statsd_for_yesterday_metrics!
statsd_for_total_editions!
statsd_for_yesterday_editions!
end
end
private
def statsd_for_all_metrics!
path... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/monitor/aggregations.rb | Ruby | mit | 19 | main | 688 | class Monitor::Aggregations
include TraceAndRecoverable
def self.run(*args)
new(*args).run
end
def run
trap do
statsd_for_all_monthly_aggregations!
statsd_for_current_month!
end
end
private
def statsd_for_all_monthly_aggregations!
path = path_for("all")
count = ::Aggregat... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/monitor/messages.rb | Ruby | mit | 19 | main | 497 | class Monitor::Messages
def self.run(routing_key)
new.run(routing_key)
end
def run(routing_key)
statsd_for_messages!(routing_key)
end
def self.increment_discarded
GovukStatsd.increment("monitor.messages.discarded")
end
private
def statsd_for_messages!(routing_key)
GovukStatsd.increment... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/monitor/dimensions.rb | Ruby | mit | 19 | main | 1,026 | class Monitor::Dimensions
include TraceAndRecoverable
def self.run(*args)
new(*args).run
end
def run
trap do
statsd_for_all_base_paths!
statsd_for_live_base_paths!
statsd_for_all_content_items!
statsd_for_live_content_items!
end
end
private
def statsd_for_live_base_pat... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/monitor/etl.rb | Ruby | mit | 19 | main | 1,072 | class Monitor::Etl
include TraceAndRecoverable
def self.run(*args)
new(*args).run
end
def run
trap do
statsd_for_performance_metrics!
statsd_for_edition_metrics!
end
end
private
def statsd_for_edition_metrics!
Metric.edition_metrics.map(&:name).each do |edition_metric|
p... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/healthchecks/search_aggregations.rb | Ruby | mit | 19 | main | 642 | module Healthchecks
class SearchAggregations
include ActiveModel::Model
include Concerns::Deactivable
attr_accessor :range
def self.build(range)
new(range:)
end
def name
"search_#{range}".to_sym
end
def status
searches.positive? ? :ok : :critical
end
def ... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/healthchecks/etl_metric_values.rb | Ruby | mit | 19 | main | 589 | module Healthchecks
class EtlMetricValues
include ActiveModel::Model
include Concerns::Deactivable
attr_accessor :metric
def self.build(metric)
new(metric:)
end
def name
"etl_metric_values_#{metric}".to_sym
end
def status
if number_of_metric_values.positive?
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/healthchecks/daily_metrics_check.rb | Ruby | mit | 19 | main | 399 | module Healthchecks
class DailyMetricsCheck
include Concerns::Deactivable
def name
:daily_metrics
end
def status
metrics.any? ? :ok : :critical
end
def message
"ETL :: no daily metrics for yesterday" if status == :critical
end
private
def metrics
@metrics... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/healthchecks/monthly_aggregations.rb | Ruby | mit | 19 | main | 457 | module Healthchecks
class MonthlyAggregations
include Concerns::Deactivable
def name
:aggregations
end
def status
aggregations.positive? ? :ok : :critical
end
def message
"ETL :: no monthly aggregations of metrics for yesterday" if status == :critical
end
private
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/healthchecks/concerns/deactivable.rb | Ruby | mit | 19 | main | 436 | require "active_support/concern"
module Healthchecks::Concerns::Deactivable
extend ActiveSupport::Concern
included do
def enabled?
healthchecks_enabled? && within_time_range?
end
private
def healthchecks_enabled?
ENV["ETL_HEALTHCHECK_ENABLED"] == "1"
end
def within_time_range?... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/feedex/processor.rb | Ruby | mit | 19 | main | 1,699 | class Etl::Feedex::Processor
include TraceAndRecoverable
def self.process(*args, **kwargs)
new(*args, **kwargs).process
end
def initialize(date:)
@date = date
end
def process
time_and_trap(process: :feedex) do
extract_events
load_metrics
end
end
private
BATCH_SIZE = 5_00... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/feedex/service.rb | Ruby | mit | 19 | main | 1,084 | require "gds_api/support_api"
class Etl::Feedex::Service
attr_reader :date, :batch_size, :support_api
def self.find_in_batches(*args, &block)
new(*args).find_in_batches(&block)
end
def initialize(date, batch_size, support_api = nil)
@date = date
@batch_size = batch_size
@support_api = support... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/ga/bigquery.rb | Ruby | mit | 19 | main | 574 | require "google/cloud/bigquery"
require "googleauth"
class Etl::GA::Bigquery
include Google::Auth
def self.build
new.build
end
def build
credentials = {
"client_email" => ENV["BIGQUERY_CLIENT_EMAIL"],
"private_key" => ENV["BIGQUERY_PRIVATE_KEY"],
}
Google::Cloud::Bigquery.new(
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/ga/user_feedback_service.rb | Ruby | mit | 19 | main | 946 | class Etl::GA::UserFeedbackService
def self.find_in_batches(*args, **kwargs, &block)
new.find_in_batches(*args, **kwargs, &block)
end
def find_in_batches(date:, batch_size: 10_000, &block)
fetch_data(date:)
.lazy
.map(&:stringify_keys)
.map(&method(:append_labels))
.each_slice(bat... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/ga/internal_search_processor.rb | Ruby | mit | 19 | main | 1,459 | require_dependency "concerns/trace_and_recoverable"
class Etl::GA::InternalSearchProcessor
include TraceAndRecoverable
include Etl::GA::Concerns::TransformPath
def self.process(*args, **kwargs)
new(*args, **kwargs).process
end
def initialize(date:)
@date = date
end
def process
time_and_trap... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/ga/internal_search_service.rb | Ruby | mit | 19 | main | 942 | class Etl::GA::InternalSearchService
def self.find_in_batches(*args, **kwargs, &block)
new.find_in_batches(*args, **kwargs, &block)
end
def find_in_batches(date:, batch_size: 10_000, &block)
fetch_data(date:)
.lazy
.map(&:stringify_keys)
.map(&method(:append_labels))
.each_slice(b... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/ga/views_and_navigation_service.rb | Ruby | mit | 19 | main | 1,225 | class Etl::GA::ViewsAndNavigationService
PAGE_PATH_LENGTH_LIMIT = 1500
def self.find_in_batches(*args, **kwargs, &block)
new.find_in_batches(*args, **kwargs, &block)
end
def find_in_batches(date:, batch_size: 10_000, &block)
fetch_data(date:)
.lazy
.map(&:stringify_keys)
.map(&method... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/ga/user_feedback_processor.rb | Ruby | mit | 19 | main | 1,609 | require_dependency "concerns/trace_and_recoverable"
class Etl::GA::UserFeedbackProcessor
include TraceAndRecoverable
include Etl::GA::Concerns::TransformPath
def self.process(*args, **kwargs)
new(*args, **kwargs).process
end
def initialize(date:)
@date = date
end
def process
time_and_trap(p... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/ga/views_and_navigation_processor.rb | Ruby | mit | 19 | main | 1,526 | require_dependency "concerns/trace_and_recoverable"
class Etl::GA::ViewsAndNavigationProcessor
include TraceAndRecoverable
include Etl::GA::Concerns::TransformPath
def self.process(*args, **kwargs)
new(*args, **kwargs).process
end
def initialize(date:)
@date = date
end
def process
time_and_... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/ga/concerns/transform_path.rb | Ruby | mit | 19 | main | 1,037 | require "active_support/concern"
module Etl::GA::Concerns::TransformPath
extend ActiveSupport::Concern
def format_events_with_invalid_prefix
events_with_prefix = Events::GA.where("page_path ~ '^\/https:\/\/www.gov.uk'")
log(process: :ga, message: "Transforming #{events_with_prefix.count} events with page_... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/aggregations/monthly.rb | Ruby | mit | 19 | main | 1,861 | class Etl::Aggregations::Monthly
include Traceable
def self.process(*args, **kwargs)
new(*args, **kwargs).process
end
def initialize(date: Date.yesterday)
@date = date
end
def process
time(process: :aggregations_monthly) do
create_month
delete_month
aggregate_month
end
... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/aggregations/search.rb | Ruby | mit | 19 | main | 586 | class Etl::Aggregations::Search
include Traceable
def self.process(*args)
new(*args).process
end
def process
do_process(::Aggregations::SearchLastThirtyDays)
do_process(::Aggregations::SearchLastMonth)
do_process(::Aggregations::SearchLastThreeMonths)
do_process(::Aggregations::SearchLastS... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/main/main_processor.rb | Ruby | mit | 19 | main | 1,517 | class Etl::Main::MainProcessor
include Traceable
def self.process(*args, **kwargs)
new(*args, **kwargs).process
end
def self.process_aggregations(*args, **kwargs)
new(*args, **kwargs).process_aggregations
end
def initialize(date: Date.yesterday)
@date = date
end
def process
delete_ex... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/main/metrics_processor.rb | Ruby | mit | 19 | main | 1,185 | require_dependency "concerns/trace_and_recoverable"
module Etl
module Main
class MetricsProcessor
include TraceAndRecoverable
def self.process(*args, **kwargs)
new(*args, **kwargs).process
end
def initialize(date:)
@date = date
end
def process
time_a... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/edition/processor.rb | Ruby | mit | 19 | main | 1,192 | class Etl::Edition::Processor
def self.process(*args)
new(*args).process
end
def initialize(old_edition, new_edition, date = Time.zone.today)
@dimensions_date = Dimensions::Date.find_existing_or_create(date)
@old_edition = old_edition
@new_edition = new_edition
end
def process
create_new... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/edition/metadata/file_counter.rb | Ruby | mit | 19 | main | 1,548 | class Etl::Edition::Metadata::FileCounter
ALL_LINKS_XPATH = "//*[contains(@class, 'attachment-details') or contains(@class, 'form-download')]//a/@href".freeze
def initialize(body)
@body = body
end
def pdf_count
count_files(%w[pdf])
end
def doc_count
count_files(%w[doc docx docm])
end
priva... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/edition/content/parser.rb | Ruby | mit | 19 | main | 2,711 | class Etl::Edition::Content::Parser
def initialize
register_parsers
end
def self.extract_content(json, subpage_path: nil)
new.extract_content(json, subpage_path:)
end
def extract_content(json, subpage_path: nil)
return nil if json.blank?
schema = json["schema_name"]
base_path = json["ba... |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/edition/content/parsers/local_transaction.rb | Ruby | mit | 19 | main | 311 | class Etl::Edition::Content::Parsers::LocalTransaction
def parse(json)
html = []
html << json.dig("details", "introduction")
html << json.dig("details", "need_to_know")
html << json.dig("details", "more_information")
html.join(" ")
end
def schemas
%w[local_transaction]
end
end |
github | alphagov/content-data-api | https://github.com/alphagov/content-data-api | app/domain/etl/edition/content/parsers/place.rb | Ruby | mit | 19 | main | 240 | class Etl::Edition::Content::Parsers::Place
def parse(json)
html = []
html << json.dig("details", "introduction")
html << json.dig("details", "more_information")
html.join(" ")
end
def schemas
%w[place]
end
end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.