repo_name
stringlengths
6
97
path
stringlengths
3
341
text
stringlengths
8
1.02M
uk-gov-mirror/alphagov.search-admin
db/migrate/20200225114743_add_created_at_to_bet.rb
class AddCreatedAtToBet < ActiveRecord::Migration[6.0] def change add_column :bets, :created_at, :datetime Bet.reset_column_information Bet.all.each do |b| b.update!(created_at: b.set_created_at) end end end
uk-gov-mirror/alphagov.search-admin
app/services/external_content_publisher.rb
class ExternalContentPublisher def self.publish(recommended_link) payload = ExternalContentPresenter.new(recommended_link) .present_for_publishing_api Services.publishing_api.put_content(recommended_link.content_id, payload) Services.publishing_api.publish(recommended_link.content_id) end def ...
uk-gov-mirror/alphagov.search-admin
spec/controllers/recommended_links_controller_spec.rb
<gh_stars>1-10 require "spec_helper" describe RecommendedLinksController do let(:recommended_link_params) do { title: "Tax", link: "https://www.tax.service.gov.uk/", description: "Self assessment", keywords: "self, assessment, tax", } end before(:each) do stub_request(:put, /...
uk-gov-mirror/alphagov.search-admin
db/migrate/20200225114827_add_expiration_date_to_bet.rb
<reponame>uk-gov-mirror/alphagov.search-admin<gh_stars>1-10 class AddExpirationDateToBet < ActiveRecord::Migration[6.0] def change add_column :bets, :expiration_date, :datetime end end
uk-gov-mirror/alphagov.search-admin
features/step_definitions/update_publishing_api_on_recommended_link_change_steps.rb
<filename>features/step_definitions/update_publishing_api_on_recommended_link_change_steps.rb Then(/^the external link should have been published$/) do check_recommended_link_was_published(RecommendedLink.last, 1) end Then(/^the external link should have been republished$/) do check_recommended_link_was_published(...
uk-gov-mirror/alphagov.search-admin
spec/models/query_spec.rb
require "spec_helper" describe Query do describe "#is_query?" do it "should return true" do query = create(:query) expect(query.is_query?).to eq true end end describe "#query_object" do it "should return itself" do query = create(:query) expect(query.query_object).to eq query...
uk-gov-mirror/alphagov.search-admin
app/generators/elastic_search_bet_id_generator.rb
<gh_stars>1-10 class ElasticSearchBetIDGenerator def self.generate(query, match_type) "#{query}-#{match_type}" end end
uk-gov-mirror/alphagov.search-admin
spec/factories.rb
<gh_stars>1-10 FactoryBot.define do sequence :numeric_position do |n| n end factory :bet do link { "/death-and-taxes" } expiration_date { Time.zone.now + 1.day } trait(:worst) do is_best { false } end trait(:best) do is_best { true } position { generate :numeric_positi...
uk-gov-mirror/alphagov.search-admin
config/routes.rb
Rails.application.routes.draw do get "/healthcheck/live", to: proc { [200, {}, %w[OK]] } get "/healthcheck/ready", to: GovukHealthcheck.rack_response( GovukHealthcheck::ActiveRecord, ) resources :bets, except: %i[index show] do member do post :deactivate end end resources :queries resou...
uk-gov-mirror/alphagov.search-admin
app/lib/services.rb
require "gds_api/search" require "gds_api/publishing_api" module Services def self.publishing_api @publishing_api ||= GdsApi::PublishingApi.new( Plek.find("publishing-api"), bearer_token: ENV["PUBLISHING_API_BEARER_TOKEN"] || "example", ) end # TODO: update RUMMAGER_BEARER_TOKEN to SEARCH_AP...
uk-gov-mirror/alphagov.search-admin
features/step_definitions/best_bet_csv_steps.rb
<filename>features/step_definitions/best_bet_csv_steps.rb<gh_stars>1-10 When(/^I view the best bets CSV$/) do visit queries_path click_on "Download CSV" end Then(/^I should see all best bets listed in the CSV$/) do check_for_queries_in_csv_format(@queries) end
uk-gov-mirror/alphagov.search-admin
app/helpers/tag_helper.rb
<filename>app/helpers/tag_helper.rb module TagHelper # Set the page <title> and return the <h1> tag. def page_title(string) content_for :page_title, "#{string} - Search Admin" tag.h1 string, class: "page-title-with-border" end end
uk-gov-mirror/alphagov.search-admin
app/presenters/external_content_presenter.rb
<reponame>uk-gov-mirror/alphagov.search-admin class ExternalContentPresenter def initialize(recommended_link) @recommended_link = recommended_link end def present_for_publishing_api { description: @recommended_link.description, details: { hidden_search_terms: hidden_search_terms, ...
uk-gov-mirror/alphagov.search-admin
app/controllers/similar_search_results_controller.rb
class SimilarSearchResultsController < ApplicationController def new render :new, locals: default_locals end def show base_path = params[:base_path] render :show, locals: { base_path: base_path, results: MoreLikeThis.from_base_path(base_path), } resc...
uk-gov-mirror/alphagov.search-admin
db/migrate/20140501121311_create_best_bets.rb
<gh_stars>1-10 class CreateBestBets < ActiveRecord::Migration def change create_table :best_bets do |t| t.string :query t.string :match_type t.string :link t.integer :position t.string :comment t.string :source end end end
uk-gov-mirror/alphagov.search-admin
db/migrate/20161111124510_change_recommended_link_types.rb
class ChangeRecommendedLinkTypes < ActiveRecord::Migration def change change_column :recommended_links, :description, :text change_column :recommended_links, :keywords, :text end end
uk-gov-mirror/alphagov.search-admin
db/migrate/20140508123717_add_combo_index_to_best_bets.rb
<filename>db/migrate/20140508123717_add_combo_index_to_best_bets.rb class AddComboIndexToBestBets < ActiveRecord::Migration def change add_index "best_bets", %w(query match_type), name: "query_match_type_index" end end
uk-gov-mirror/alphagov.search-admin
config/initializers/zeitwerk.rb
Rails.autoloaders.each do |autoloader| autoloader.inflector.inflect( "elastic_search_bet_id_generator" => "ElasticSearchBetIDGenerator", ) end
uk-gov-mirror/alphagov.search-admin
app/models/elastic_search_bet.rb
<gh_stars>1-10 class ElasticSearchBet def initialize(query) @query = query end def header { index: { _id: id, _type: type, }, } end def body { query_field => query_string, details: details.to_json, } end def id ElasticSearchBetIDGenerator....
uk-gov-mirror/alphagov.search-admin
app/models/query.rb
class Query < ApplicationRecord MATCH_TYPES = %w[exact stemmed].freeze validates :query, presence: true validates :match_type, inclusion: { in: MATCH_TYPES } validates :query, uniqueness: { scope: :match_type, case_sensitive: true } has_many :bets, dependent: :destroy has_many :best_bets, -> { best }, cla...
uk-gov-mirror/alphagov.search-admin
db/migrate/20140604154436_add_query_id_to_bets.rb
class AddQueryIdToBets < ActiveRecord::Migration def change add_column :bets, :query_id, :integer add_column :bets, :is_best, :boolean, default: true Bet.all.each do |bet| query = Query.where(query: bet['query'], match_type: bet['match_type']).first query ||= Query.create!(query: bet['query']...
uk-gov-mirror/alphagov.search-admin
features/step_definitions/managing_results_steps.rb
<gh_stars>0 When(/^I visit the results form$/) do visit root_path click_on "Search results" end When(/^I type in a valid GOV.UK link$/) do stub_request(:get, "https://search.test.gov.uk/content?link=/make-a-sorn") .to_return(body: { "raw_source" => { "title" => "Stubbed page about SORN" } }.to_json) fill_...
uk-gov-mirror/alphagov.search-admin
features/step_definitions/best_bet_steps.rb
Given(/^I am an admin user$/) do login_as(:admin_user) end Given(/^I am a basic user$/) do login_as(:user) end When(/^I create a best bet$/) do create_query(query: "some jobs", match_type: "exact", bets: [["/jobsearch", true, 1, "a comment"]]) end When(/^I create a best bet with invalid attributes$/) do crea...
uk-gov-mirror/alphagov.search-admin
app/mailers/bets_mailer.rb
class BetsMailer < ApplicationMailer def expiring_bets_list(address, bets) return if bets.empty? @when = bets.first.expiration_date @grouped_bets = bets.each_with_object({}) do |bet, grouped| grouped[bet.query.display_name] ||= [] grouped[bet.query.display_name] << bet.link end view_...
uk-gov-mirror/alphagov.search-admin
db/schema.rb
<filename>db/schema.rb # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # This file is the source Rails uses to define your schem...
uk-gov-mirror/alphagov.search-admin
app/validators/url_validator.rb
require "uri" class UrlValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) uri = parse(value) unless uri&.host msg = options[:message] || (uri ? "does not have a valid host" : "is an invalid URL") record.errors[attribute] << msg end end private def parse(v...
uk-gov-mirror/alphagov.search-admin
lib/tasks/reindex_best_bets.rake
desc "Resend all local queries to search_api to be reindexed" task reindex_best_bets: :environment do message = <<-MSG Rebuilding the elasticsearch index will just resend all locally stored best bets across to be inserted in to elasticsearch. This means that any orphaned entries in the elasticsearch index...
uk-gov-mirror/alphagov.search-admin
features/step_definitions/query_steps.rb
<gh_stars>1-10 When(/^I create a new query$/) do create_query(query: "jobs", match_type: "exact") end Then(/^the query should be listed on the query index$/) do check_for_query_on_index_page(query: "jobs", match_type: "exact") end When(/^I edit the query$/) do edit_query(query_text: @query.query, new_query_text...
uk-gov-mirror/alphagov.search-admin
spec/generators/elastic_search_bet_id_generator_spec.rb
require "spec_helper" describe ElasticSearchBetIDGenerator do describe ".generate(query, match_type)" do it "concatenates the `query` and `match_type` with a hyphen" do generated_id = ElasticSearchBetIDGenerator.generate("jobs", "exact") expect(generated_id).to eq("jobs-exact") end end end
uk-gov-mirror/alphagov.search-admin
spec/models/elastic_search_bet_spec.rb
<reponame>uk-gov-mirror/alphagov.search-admin require "spec_helper" describe ElasticSearchBet do let(:query) { create(:query, query: "jobs", match_type: "exact") } before do create(:bet, :best, link: "/jobs/inactive-jobs", position: 3, query: query, permanent: true, expiration_date: nil).deactivate creat...
uk-gov-mirror/alphagov.search-admin
spec/services/external_content_publisher_spec.rb
<filename>spec/services/external_content_publisher_spec.rb<gh_stars>1-10 require "spec_helper" RSpec.describe ExternalContentPublisher do let(:link) do RecommendedLink.new( content_id: "some-content-id", description: "Public data to help people understand how the government works", link: "http:...
uk-gov-mirror/alphagov.search-admin
spec/mailers/bets_mailer_spec.rb
require "spec_helper" describe BetsMailer, type: :mailer do describe "expiring_bets_list" do let(:address) { "<EMAIL>" } let(:expires) { Time.zone.now } let(:bets) do test_stemmed = create(:query, query: "test", match_type: "stemmed") test_exact = create(:query, query: "test", match_typ...
uk-gov-mirror/alphagov.search-admin
spec/models/elastic_search_recommended_link_spec.rb
<gh_stars>1-10 require "spec_helper" describe ElasticSearchRecommendedLink do let(:recommended_link) do create( :recommended_link, title: "Tax", link: "https://www.tax.service.gov.uk/", description: "Self assessment", keywords: "self, assessment, tax", content_id: SecureRandom...
uk-gov-mirror/alphagov.search-admin
app/controllers/queries_controller.rb
class QueriesController < ApplicationController def index @queries = Query.includes(:best_bets, :worst_bets).order(%i[query match_type]) respond_to do |format| format.html format.csv { send_data @queries.to_csv } end end def new; end def create query = Query.new(query_params) ...
uk-gov-mirror/alphagov.search-admin
spec/helpers/table_for_spec.rb
require "spec_helper" describe TableHelper do describe "#table_for" do it "generates a table for a hash" do hash = { a: "b", c: "d" } table = helper.table_for(hash) expect(table).to eql( '<table class="table key-value-table"><tr><td>a</td><td>b</td></tr><tr><td>c</td><td>d</td></tr></...
uk-gov-mirror/alphagov.search-admin
app/helpers/application_helper.rb
module ApplicationHelper def navigation_items return [] unless current_user items = [ { text: "Queries", href: queries_path, active: is_current?(queries_path), }, { text: "External links", href: recommended_links_path, active: is_current?(reco...
uk-gov-mirror/alphagov.search-admin
app/helpers/table_helper.rb
<reponame>uk-gov-mirror/alphagov.search-admin<filename>app/helpers/table_helper.rb<gh_stars>1-10 module TableHelper def table_for(hash) tag.table class: "table key-value-table" do rows = hash.map do |k, v| tag.tr do tag.td(k) + tag.td(display_value(v)) end end rows.joi...
uk-gov-mirror/alphagov.search-admin
db/migrate/20140502085848_add_user_id_to_best_bet.rb
class AddUserIdToBestBet < ActiveRecord::Migration def change remove_column :best_bets, :source add_column :best_bets, :user_id, :integer add_column :best_bets, :manual, :boolean, default: false end end
uk-gov-mirror/alphagov.search-admin
app/workers/expired_bet_worker.rb
class ExpiredBetWorker include Sidekiq::Worker def perform recently_expired_bets.find_each do |bet| SearchApiSaver.new(bet).destroy(action: :deactivate) end end private # job runs every hour but checks for bets which expired in the last # 90 minutes - this is to reduce the chance of something...
uk-gov-mirror/alphagov.search-admin
spec/controllers/bets_controller_spec.rb
require "spec_helper" describe BetsController do before do allow(Services.search_api).to receive(:add_document) allow(Services.search_api).to receive(:delete_document) end let(:query) { create(:query) } let(:permanent_bet_params) do { query_id: query.id, link: "/visas-and-immigration"...
uk-gov-mirror/alphagov.search-admin
app/models/elastic_search_mlt_result.rb
class ElasticSearchMltResult include ActiveModel::Model VALID_FIELDS = %w[ title link format es_score content_store_document_type ].freeze attr_accessor(*VALID_FIELDS.map(&:to_sym)) end
uk-gov-mirror/alphagov.search-admin
spec/lib/travel_advice_bets_importer_spec.rb
<reponame>uk-gov-mirror/alphagov.search-admin require "spec_helper" require "travel_advice_bets_importer" RSpec.describe TravelAdviceBetsImporter do let(:csv_data) do [ ["Angola", "/world/angola"], ["Belgium", "/world/belgium"], ["Spain", "/world/spain"], ] end let(:logger) { double(:lo...
uk-gov-mirror/alphagov.search-admin
app/helpers/icon_helper.rb
module IconHelper # http://getbootstrap.com/components/#glyphicons-glyphs def icon(icon_name) tag.i "", class: "glyphicon glyphicon-#{icon_name}" end end
uk-gov-mirror/alphagov.search-admin
app/controllers/bets_controller.rb
<gh_stars>1-10 class BetsController < ApplicationController def create attrs = param_parser.bet_attributes @bet = Bet.new(attrs) unless admin_user? @bet.set_defaults end saver = SearchApiSaver.new(@bet) if saver.save redirect_to query_path(@bet.query), notice: "Bet created" el...
uk-gov-mirror/alphagov.search-admin
app/parsers/date_parser.rb
<gh_stars>1-10 class DateParser attr_reader :day, :month, :year def initialize(day:, month:, year:) @day = day @month = month @year = year end def date Time.zone.local(year, month, day) rescue ArgumentError "" end end
uk-gov-mirror/alphagov.search-admin
spec/services/more_like_this_spec.rb
require "spec_helper" RSpec.describe MoreLikeThis do describe ".from_base_path" do context "with an unknown base path in search" do before do allow(Services.search_api).to receive(:search) .with( filter_link: "/unknown", fields: %w[taxons], ) .a...
uk-gov-mirror/alphagov.search-admin
db/migrate/20140728094001_lowercase_queries.rb
class LowercaseQueries < ActiveRecord::Migration def change Query.all.each do |query| query.update_attribute(:query, query.query.downcase) end query_groups = Query.all.group_by { |q| [q.query, q.match_type] } puts "Checking for duplicated queries" puts query_groups.select { |_, queries| ...
uk-gov-mirror/alphagov.search-admin
app/controllers/results_controller.rb
class ResultsController < ApplicationController def index; end def show @path = params[:base_path] @path = URI.parse(@path).path if @path.starts_with?("http") @document = Services.search_api.get("/content?link=#{@path}") rescue GdsApi::HTTPNotFound flash[:error] = "That URL wasn't found." red...
uk-gov-mirror/alphagov.search-admin
db/migrate/20171214153332_add_content_id_to_recommended_links.rb
<filename>db/migrate/20171214153332_add_content_id_to_recommended_links.rb class AddContentIdToRecommendedLinks < ActiveRecord::Migration[5.0] def up add_column :recommended_links, :content_id, "char(36)" add_index :recommended_links, :content_id, unique: true RecommendedLink.all.each do |link| lin...
uk-gov-mirror/alphagov.search-admin
db/migrate/20140604142849_create_query.rb
class CreateQuery < ActiveRecord::Migration def change create_table :queries do |t| t.string :query t.string :match_type t.timestamps end end end
uk-gov-mirror/alphagov.search-admin
features/step_definitions/recommended_links_steps.rb
<gh_stars>1-10 Given(/^an external link exists named "(.*)" with link "(.*)"$/) do |title, link| @recommended_link = create(:recommended_link, title: title, link: link) end Given(/^there are some external links$/) do @recommended_links = (1..3).map do |n| create(:recommended_link, title: "Tax online #{n}", lin...
uk-gov-mirror/alphagov.search-admin
spec/services/search_api_saver_spec.rb
<filename>spec/services/search_api_saver_spec.rb require "spec_helper" RSpec.describe SearchApiSaver do let(:query) { create(:query) } let(:search_api_saver) { described_class.new(query) } describe "#destroy" do context "when passed an unrecognised action" do it "raises a custom InvalidAction Error" d...
uk-gov-mirror/alphagov.search-admin
features/step_definitions/recommended_links_csv_steps.rb
When(/^I view the external links CSV$/) do visit recommended_links_path click_on "Download CSV" end Then(/^I should see all external links listed in the CSV$/) do check_for_recommended_links_in_csv_format(@recommended_links) end
uk-gov-mirror/alphagov.search-admin
db/migrate/20160818081220_add_reference_for_user_id_to_best_bets.rb
<gh_stars>1-10 class AddReferenceForUserIdToBestBets < ActiveRecord::Migration def up rename_column :bets, :user_id, :old_user_id add_reference :bets, :user Bet.all.each do |bet| bet.user_id = bet.old_user_id bet.save! end remove_column :bets, :old_user_id end def down renam...
uk-gov-mirror/alphagov.search-admin
features/step_definitions/similar_search_results_steps.rb
When(/^I visit the similar search results form$/) do visit root_path click_on "Similar search results" end When(/^I type in a valid GOV\.UK link with related items$/) do stub_request( :get, "https://search.test.gov.uk/search.json?fields%5B%5D=taxons&filter_link=/guidance/pupil-premium-reviews", ).to_re...
uk-gov-mirror/alphagov.search-admin
spec/presenters/external_content_presenter_spec.rb
require "spec_helper" RSpec.describe ExternalContentPresenter do context "for the publishing API" do it "presents minimal external content to match the schema" do payload = ExternalContentPresenter.new(recommended_link).present_for_publishing_api expect(payload[:description]).to eq("Public data to h...
uk-gov-mirror/alphagov.search-admin
app/workers/notify_expiring_bets_worker.rb
class NotifyExpiringBetsWorker THRESHOLD = 7.days include Sidekiq::Worker def perform addresses.each do |address| BetsMailer.new.expiring_bets_list(address, soon_to_expire_bets).deliver_now end # also notify bet creators (if they're not in the 'addresses' # list). grouped_bets = soon_...
uk-gov-mirror/alphagov.search-admin
lib/tasks/publish_external_links.rake
<gh_stars>1-10 desc "Ensure all external links in the database are present in the publishing platform" namespace :publish_external_links do desc "Send external links to the Publishing API" task publishing_api: :environment do RecommendedLink.all.each do |link| puts link.link ExternalContentPublisher...
uk-gov-mirror/alphagov.search-admin
spec/spec_helper.rb
<reponame>uk-gov-mirror/alphagov.search-admin<gh_stars>1-10 # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= "test" ENV["GOVUK_APP_DOMAIN"] = "test.gov.uk" ENV["GOVUK_ASSET_ROOT"] = "http://static.test.gov.uk" require "simplecov" SimpleCov.start "rails" require File.expa...
uk-gov-mirror/alphagov.search-admin
app/models/recommended_link.rb
class RecommendedLink < ApplicationRecord validates :title, :link, :description, :content_id, presence: true validates :link, uniqueness: { case_sensitive: true }, url: true validates :content_id, uniqueness: { case_sensitive: true } def format uri = URI(link) if uri.scheme.nil? uri = URI("https:...
uk-gov-mirror/alphagov.search-admin
db/migrate/20200228171904_add_permanent_to_bet.rb
class AddPermanentToBet < ActiveRecord::Migration[6.0] def change add_column :bets, :permanent, :bool, default: false Bet.reset_column_information Bet.all.each do |b| b.update!(permanent: true) end end end
uk-gov-mirror/alphagov.search-admin
db/migrate/20140604154109_rename_best_bet.rb
<filename>db/migrate/20140604154109_rename_best_bet.rb class RenameBestBet < ActiveRecord::Migration def change rename_table :best_bets, :bets end end
uk-gov-mirror/alphagov.search-admin
config/initializers/services_and_listeners.rb
require "gds_api/search" # Extend the adapters to allow us to request URLs directly. module GdsApi class Search < Base def get(path) request_url = "#{base_url}#{path}" get_json(request_url) end def delete!(path) request_url = "#{base_url}#{path}" delete_json(request_url) end ...
uk-gov-mirror/alphagov.search-admin
spec/controllers/queries_controller_spec.rb
<gh_stars>1-10 require "spec_helper" describe QueriesController do before do allow(Services.search_api).to receive(:add_document) allow(Services.search_api).to receive(:delete_document) end let(:query_params) { { query: "jobs", match_type: "exact" } } describe "#create" do context "on failure" do...
uk-gov-mirror/alphagov.search-admin
app/parsers/bet_params_parser.rb
<reponame>uk-gov-mirror/alphagov.search-admin class BetParamsParser attr_reader :bet_params, :user_id def initialize(bet_params, user_id) @bet_params = bet_params @user_id = user_id end def bet_attributes bet_params.merge( expiration_date: date_attributes, user_id: user_id, manua...
uk-gov-mirror/alphagov.search-admin
features/step_definitions/navigation_steps.rb
Given(/^I am viewing a specific query$/) do query = create(:query) visit query_path(query) end Then(/^I can click a link to navigate to the index of queries$/) do within(".govuk-breadcrumbs__list") do click_link "Queries" end expect(current_path).to eq queries_path end Given(/^I am viewing a specific e...
uk-gov-mirror/alphagov.search-admin
app/controllers/recommended_links_controller.rb
<filename>app/controllers/recommended_links_controller.rb class RecommendedLinksController < ApplicationController def index @recommended_links = RecommendedLink.order([:link]) respond_to do |format| format.html format.csv { send_data @recommended_links.to_csv } end end def new @reco...
uk-gov-mirror/alphagov.search-admin
app/validators/bet_date_validator.rb
<reponame>uk-gov-mirror/alphagov.search-admin class BetDateValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) @record = record @attribute = attribute @value = value validations end private attr_reader :record, :attribute, :value def validations if expirati...
uk-gov-mirror/alphagov.search-admin
features/support/users.rb
<reponame>uk-gov-mirror/alphagov.search-admin<filename>features/support/users.rb def login_as(user) GDS::SSO.test_user = create(user) Capybara.reset_sessions! end def current_user GDS::SSO.test_user || User.first end def reset_authentication GDS::SSO.test_user = nil Capybara.reset_sessions! end
uk-gov-mirror/alphagov.search-admin
features/support/best_bets.rb
<filename>features/support/best_bets.rb def create_query(user: nil, query: nil, match_type: nil, bets: []) visit queries_path click_on "New query" fill_in "Query", with: query if query select match_type.humanize, from: "Match type" if match_type click_on "Save" unless user == :admin check_query_page_...
uk-gov-mirror/alphagov.search-admin
app/services/search_url.rb
class SearchUrl def self.for(search_term) base_url = Plek.current.website_root search_term = CGI.escape(search_term) random = SecureRandom.hex(10) "#{base_url}/search/all?keywords=#{search_term}&order=relevance&debug_score=1&cachebust=#{random}" end end
uk-gov-mirror/alphagov.search-admin
lib/tasks/import_travel_advice_best_bets.rake
require "csv" require "travel_advice_bets_importer" namespace :travel_advice do desc "Imports travel advice best bets into search_api from csv data." task :import_best_bets, %i[data_path user_name] => :environment do |_, args| data = CSV.read(args[:data_path]) user = User.find_by(name: args[:user_name]) ...
uk-gov-mirror/alphagov.search-admin
spec/models/elastic_search_mlt_result_spec.rb
<filename>spec/models/elastic_search_mlt_result_spec.rb require "spec_helper" describe ElasticSearchMltResult do let(:attributes) do { title: "A related link", link: "/related-link", format: "guide", es_score: 20.21, content_store_document_type: "guide", } end let(:result) {...
uk-gov-mirror/alphagov.search-admin
features/support/rummager.rb
<reponame>uk-gov-mirror/alphagov.search-admin Before "@stub_best_bets" do @search_api = double(:search_api, delete_document: true, add_document: true) allow(Services).to receive(:search_api).and_return(@search_api) end Before "@stub_best_bets_with_404" do @search_api = double(:search_api, add_document: true) a...
uk-gov-mirror/alphagov.search-admin
db/migrate/20151016132421_allow_longer_comments.rb
class AllowLongerComments < ActiveRecord::Migration def change change_column :bets, :comment, :text end end
uk-gov-mirror/alphagov.search-admin
app/helpers/buttons_helper.rb
<filename>app/helpers/buttons_helper.rb module ButtonsHelper def delete_button(text, path, is_inline = false) button_to text, path, method: :delete, class: "gem-c-button govuk-button govuk-button--warning", form_class: ("app-display-inline" if is_inline) e...
uk-gov-mirror/alphagov.search-admin
app/workers/delete_old_bets_worker.rb
class DeleteOldBetsWorker # All expired bets older than this, or all disabled bets last # updated longer ago than this, are deleted OLD_BET_THRESHOLD = 30.days include Sidekiq::Worker def perform queries = old_expired_bets.map(&:query_id).uniq + old_disabled_bets.map(&:query_id).uniq old_expired_be...
uk-gov-mirror/alphagov.search-admin
db/migrate/20160815115453_add_recommended_links.rb
<reponame>uk-gov-mirror/alphagov.search-admin class AddRecommendedLinks < ActiveRecord::Migration def change create_table :recommended_links do |t| t.string :title t.string :link t.string :description t.string :keywords t.text :comment t.references :user end end end
uk-gov-mirror/alphagov.search-admin
spec/models/recommended_link_spec.rb
require "spec_helper" describe RecommendedLink do describe "#format" do it "uses recommended-link format if it is external to gov.uk" do recommended_link = create( :recommended_link, link: "https://www.google.com", ) expect(recommended_link.format).to eq "recommended-link" e...
jmelero08/workout_planner_backend
app/models/workout_plan.rb
<filename>app/models/workout_plan.rb class WorkoutPlan < ApplicationRecord belongs_to :category validates :title, presence: true end
jmelero08/workout_planner_backend
config/routes.rb
Rails.application.routes.draw do namespace :api do namespace :v1 do resources :workout_plans resources :categories, only: [:index] end end end
jmelero08/workout_planner_backend
app/controllers/api/v1/workout_plans_controller.rb
<reponame>jmelero08/workout_planner_backend class Api::V1::WorkoutPlansController < ApplicationController def index workout_plans = WorkoutPlan.all #render json: workout_plans render json: WorkoutPlanSerializer.new(workout_plans) end def create workout_plan = WorkoutPlan.n...
jmelero08/workout_planner_backend
app/models/category.rb
class Category < ApplicationRecord has_many :workout_plans, dependent: :destroy end
jmelero08/workout_planner_backend
db/seeds.rb
# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). # # Examples: # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # ...
jmelero08/workout_planner_backend
app/serializers/workout_plan_serializer.rb
class WorkoutPlanSerializer include FastJsonapi::ObjectSerializer attributes :title, :description, :image_url, :category_id, :category end
jmelero08/workout_planner_backend
db/migrate/20210718180617_remove_category_id_from_workout_plans_table.rb
class RemoveCategoryIdFromWorkoutPlansTable < ActiveRecord::Migration[6.1] def change remove_column :workout_plans, :category_id, :integer end end
matiaskorhonen/s3itch_client
spec/spec_helper.rb
<filename>spec/spec_helper.rb require "simplecov" SimpleCov.start require "bundler" Bundler.setup require "rspec" require "webmock/rspec" require "s3itch_client"
matiaskorhonen/s3itch_client
spec/s3itch_client_spec.rb
<reponame>matiaskorhonen/s3itch_client # encoding: UTF-8 require "spec_helper" describe S3itchClient do let(:kitten_path) { File.expand_path("../support/kitten.jpeg", __FILE__).to_s } describe ".indifferent_hash" do let(:hash) do S3itchClient.indifferent_hash({ :symbol => "Foo", "string...
matiaskorhonen/s3itch_client
lib/s3itch_client/cli.rb
require "s3itch_client" require "s3itch_client/version" require "optparse" require "yaml" module S3itchClient module CLI CONFIG_PATH = File.expand_path "~/.s3itch.yml" def self.upload(argv, filepath) S3itchClient.upload(filepath, parse_options(argv)) end def self.parse_options(argv) opt...
matiaskorhonen/s3itch_client
lib/s3itch_client.rb
<reponame>matiaskorhonen/s3itch_client<filename>lib/s3itch_client.rb require "s3itch_client/version" require "i18n" require "net/http" require "securerandom" require "uri" require "yaml" module S3itchClient def self.upload(filepath, options={}) options = indifferent_hash(options) unless options[:url] ...
pyoor/metasploit-framework
modules/exploits/multi/http/glossword_upload_exec.rb
<reponame>pyoor/metasploit-framework<gh_stars>1-10 ## # This module requires Metasploit: http//metasploit.com/download # Current source: https://github.com/rapid7/metasploit-framework ## require 'msf/core' class Metasploit3 < Msf::Exploit::Remote Rank = ExcellentRanking include Msf::Exploit::Remote::HttpClient ...
joekunin/TumblrQueue
app.rb
<filename>app.rb # gem install xmp exifr open-uri tumblr_client require 'dotenv' require 'xmp' require 'exifr' require 'open-uri' require 'tumblr_client' # Bootstrap and configuration Dotenv.load #authenticate tumblr plugin Tumblr.configure do |config| config.consumer_key = ENV['TUMBLR_CONSUMER_KEY'] config.consu...
joekunin/TumblrQueue
gem/tumblrqueue/lib/tumblrqueue.rb
<gh_stars>0 require "tumblrqueue/version" require "open-uri" module Tumblrqueue # Your code goes here... end
omikolaj/neos-fair-api
db/seeds.rb
<filename>db/seeds.rb # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). # # Examples: # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of...
omikolaj/neos-fair-api
app/controllers/api/users_controller.rb
class Api::UsersController < ApplicationController include FormatPrice def create user = User.new(user_params) if user.save auth_token = auth_token(user.id) render json: {token: auth_token, expiresIn: ENV["EXPIRES_IN"], userID: user.id, status: 201}, status: 201 ...
omikolaj/neos-fair-api
app/serializers/ad_item_serializer.rb
<reponame>omikolaj/neos-fair-api class AdItemSerializer < ActiveModel::Serializer attributes :id, :title, :condition end
omikolaj/neos-fair-api
app/models/item.rb
class Item < ApplicationRecord belongs_to :ad_item has_one :ad, :through => :ad_item has_one :user, :through => :ad validates :title, presence: true end
omikolaj/neos-fair-api
app/serializers/ad_serializer.rb
<filename>app/serializers/ad_serializer.rb class AdSerializer < ActiveModel::Serializer attributes :id, :title, :type, :description, :published has_one :user, serializer: AdUserSerializer has_one :item, serializer: AdItemSerializer has_one :category, serializer: AdCategorySerializer belongs_to :ad_item, seria...
omikolaj/neos-fair-api
app/serializers/user_ad_item_serializer.rb
<reponame>omikolaj/neos-fair-api class UserAdItemSerializer < ActiveModel::Serializer attributes :id, :title end
omikolaj/neos-fair-api
app/models/ad.rb
<filename>app/models/ad.rb<gh_stars>0 class Ad < ApplicationRecord scope :drafts, -> { where(type: 'Draft')} belongs_to :ad_item has_one :user, :through => :ad_item has_one :item, :through => :ad_item has_one :category, :through => :ad_item validates :title, :description, presence: true, length:...