From 48e5afaad5b9d53b44b068b8e198c5c99c12ce31 Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Tue, 21 Aug 2018 02:51:15 -0700 Subject: [PATCH 01/17] add mysql gem --- Gemfile | 1 + Gemfile.lock | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 5d1817a7..1f978f37 100644 --- a/Gemfile +++ b/Gemfile @@ -17,6 +17,7 @@ gem 'sass-rails', '~> 5.0' gem 'httparty', '0.13.7' gem 'exception_notification', '~> 4.1' gem 'rails_logger', git: 'git@git.liveramp.net:RailsRepos/rails_logger.git' +gem 'mysql2', '~> 0.4' group :development, :test do gem 'capybara' diff --git a/Gemfile.lock b/Gemfile.lock index d7259102..571c03f8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -117,6 +117,7 @@ GEM minitest (5.10.1) multi_json (1.12.1) multi_xml (0.5.5) + mysql2 (0.4.4) newrelic_rpm (3.16.2.321) nio4r (1.2.1) nokogiri (1.7.0.1) @@ -243,6 +244,7 @@ DEPENDENCIES jquery-rails (~> 4.1) jquery-ui-rails (~> 5.0) letter_opener + mysql2 (~> 0.4) newrelic_rpm (~> 3.14) passenger (~> 5.0) pry-byebug @@ -260,4 +262,4 @@ DEPENDENCIES uglifier (= 2.7.2) BUNDLED WITH - 1.14.6 + 1.16.0 From a5461113ddee13ae520c34459430a0790be9e20c Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Tue, 21 Aug 2018 03:09:43 -0700 Subject: [PATCH 02/17] gitignore secrets yaml --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 70737010..78d1a466 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ tmp/ node_modules/ *bundle.js npm-debug.log +config/secrets.yml From 291b38a7ec55abd513a9cd94e98f179c8700037d Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Tue, 21 Aug 2018 03:10:41 -0700 Subject: [PATCH 03/17] some seed stuff --- Gemfile.lock | 2 +- config/application.rb | 1 + config/database.yml | 32 ++++++++++++++++++++++++++++++++ config/secrets.yml | 28 +++++++--------------------- script/fodor | 10 ++++++++++ 5 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 config/database.yml create mode 100644 script/fodor diff --git a/Gemfile.lock b/Gemfile.lock index 571c03f8..9dd2fd28 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -163,7 +163,7 @@ GEM method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (12.0.0) + rake (12.3.1) redis (3.3.2) redis-actionpack (5.0.1) actionpack (>= 4.0, < 6) diff --git a/config/application.rb b/config/application.rb index 08a6c195..20474204 100644 --- a/config/application.rb +++ b/config/application.rb @@ -4,6 +4,7 @@ require 'action_mailer/railtie' require 'action_controller/railtie' require 'sprockets/railtie' +require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 00000000..b70ecde6 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,32 @@ +production: + database: go_links_production + username: go_links_user + password: "<%= Rails.application.secrets.go_links_password %>" + host: "<%= Rails.application.secrets.go_links_host %>" + encoding: utf8 + reconnect: 'true' + adapter: mysql2 + retries: 0 + pool: 5 + reaping_frequency: 60 + wait_timeout: 28800 +development: + database: go_links_development + username: go_links_user + password: "<%= Rails.application.secrets.go_links_password %>" + host: "<%= Rails.application.secrets.go_links_host %>" + encoding: utf8 + reconnect: 'true' + adapter: mysql2 + retries: 0 + pool: 5 + reaping_frequency: 60 + wait_timeout: 28800 +test: + adapter: mysql2 + username: root + password: + host: 127.0.0.1 + database: go_links_test + encoding: utf8 + reconnect: true diff --git a/config/secrets.yml b/config/secrets.yml index bb49dc0d..e5cd1303 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -1,22 +1,8 @@ -# Be sure to restart your server when you modify this file. - -# Your secret key is used for verifying the integrity of signed cookies. -# If you change this key, all old signed cookies will become invalid! - -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -# You can use `rake secret` to generate a secure secret key. - -# Make sure the secrets in this file are kept private -# if you're sharing your code publicly. - +production: # we use production rails env in development deploys + secret_key_base: 9vrWgICyWsKKlFQNwXNe69TFMbCvTLIYGChVMyCl + go_links_host: go-links-db.liveramp.net + rldb_password: development: - secret_key_base: 63c8eb30a30e1d4f4224a96da78c4bdb859f37f632962e1515cb7023b8ec2adb6e5063025c9cb4ab3d5cacfefe5ea4250ad5e5cd4fd7a2addfe48f52e2e76553 - -test: - secret_key_base: 6e8747796758022e74d47ea2c9cec5dabec6a51f9f8b0fd21b9518b1c3e473e52be58ffed71d27ae8bd7b974b6af4cec3267c9e59102df1af9892d2a038860b8 - -# Do not keep production secrets in the repository, -# instead read values from the environment. -production: - secret_key_base: 63c8eb30a30e1d4f4224a96da78c4bdb859f37f632962e1515cb7023b8ec2adb6e5063025c9cb4ab3d5cacfefe5ea4250ad5e5cd4fd7a2addfe48f52e2e76553 + secret_key_base: uQ7mOU0Al87OZMwAp3gVhmPxf5h3CrRP2kgznkTw + go_links_host: go-links-db-dev.liveramp.net + rldb_password: diff --git a/script/fodor b/script/fodor new file mode 100644 index 00000000..e7a1e0a2 --- /dev/null +++ b/script/fodor @@ -0,0 +1,10 @@ +#!/bin/bash + +hvault_path=secret/fodor/go_links/secrets.yml + +echo 'Grabbing configs for go_links [development] from hvault...' +if ! vault read -field=development $hvault_path > config/secrets.yml; then + echo '*** Failed to fetch secrets from Hashicorp Vault! ***' + echo 'You might need to auth, or re-auth, with the following command:' + echo ' vault auth -method=ldap' +fi From 2be9044919a9b2f985d58399ce56a3c5c183b7c1 Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Tue, 21 Aug 2018 03:17:25 -0700 Subject: [PATCH 04/17] create links migration and schema --- config/database.yml | 8 ++++++++ db/migrate/20180821101102_create_links.rb | 11 +++++++++++ db/schema.rb | 24 +++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 db/migrate/20180821101102_create_links.rb create mode 100644 db/schema.rb diff --git a/config/database.yml b/config/database.yml index b70ecde6..b98d7451 100644 --- a/config/database.yml +++ b/config/database.yml @@ -22,6 +22,14 @@ development: pool: 5 reaping_frequency: 60 wait_timeout: 28800 +local: + adapter: mysql2 + username: root + password: + database: go_links_local + host: localhost + encoding: utf8 + reconnect: true test: adapter: mysql2 username: root diff --git a/db/migrate/20180821101102_create_links.rb b/db/migrate/20180821101102_create_links.rb new file mode 100644 index 00000000..2b354867 --- /dev/null +++ b/db/migrate/20180821101102_create_links.rb @@ -0,0 +1,11 @@ +class CreateLinks < ActiveRecord::Migration[5.0] + def change + create_table :links do |t| + t.string :alias + t.string :url + t.string :owner + t.text :description + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 00000000..91ea5381 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,24 @@ +# 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. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20180821101102) do + + create_table "links", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| + t.string "alias" + t.string "url" + t.string "owner" + t.text "description", limit: 65535 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end From 33f9b024be5f11a944712728f66f9544b01f8e6c Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Tue, 21 Aug 2018 03:28:41 -0700 Subject: [PATCH 05/17] add link model with url validation --- Gemfile | 1 + Gemfile.lock | 4 ++++ app/models/.keep | 0 app/models/concerns/.keep | 0 app/models/link.rb | 3 +++ 5 files changed, 8 insertions(+) delete mode 100644 app/models/.keep delete mode 100644 app/models/concerns/.keep create mode 100644 app/models/link.rb diff --git a/Gemfile b/Gemfile index 1f978f37..db403a8c 100644 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,7 @@ gem 'httparty', '0.13.7' gem 'exception_notification', '~> 4.1' gem 'rails_logger', git: 'git@git.liveramp.net:RailsRepos/rails_logger.git' gem 'mysql2', '~> 0.4' +gem 'validate_url', '~> 1.0' group :development, :test do gem 'capybara' diff --git a/Gemfile.lock b/Gemfile.lock index 9dd2fd28..7537625a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -220,6 +220,9 @@ GEM uglifier (2.7.2) execjs (>= 0.3.0) json (>= 1.8.0) + validate_url (1.0.2) + activemodel (>= 3.0.0) + addressable websocket (1.2.3) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) @@ -260,6 +263,7 @@ DEPENDENCIES shoulda sprockets-rails (~> 2.0) uglifier (= 2.7.2) + validate_url (~> 1.0) BUNDLED WITH 1.16.0 diff --git a/app/models/.keep b/app/models/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/app/models/link.rb b/app/models/link.rb new file mode 100644 index 00000000..b1cab814 --- /dev/null +++ b/app/models/link.rb @@ -0,0 +1,3 @@ +class Link < ActiveRecord::Base + validates :url, url: true +end From 0a4eba98a7c1ba6031e9286475879a38385998d6 Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Tue, 21 Aug 2018 03:49:32 -0700 Subject: [PATCH 06/17] make link spec, make non-null:true where important --- .rspec | 2 ++ Gemfile | 2 ++ Gemfile.lock | 19 ++++++++++ db/migrate/20180821101102_create_links.rb | 6 ++-- db/schema.rb | 6 ++-- spec/app/models/link_spec.rb | 42 +++++++++++++++++++++++ spec/factories/links.rb | 9 +++++ spec/spec_helper.rb | 14 ++++++++ test/controllers/.keep | 0 test/fixtures/.keep | 0 test/helpers/.keep | 0 test/integration/.keep | 0 test/mailers/.keep | 0 test/models/.keep | 0 test/test_helper.rb | 10 ------ 15 files changed, 94 insertions(+), 16 deletions(-) create mode 100644 .rspec create mode 100644 spec/app/models/link_spec.rb create mode 100644 spec/factories/links.rb create mode 100644 spec/spec_helper.rb delete mode 100644 test/controllers/.keep delete mode 100644 test/fixtures/.keep delete mode 100644 test/helpers/.keep delete mode 100644 test/integration/.keep delete mode 100644 test/mailers/.keep delete mode 100644 test/models/.keep delete mode 100644 test/test_helper.rb diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..83e16f80 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/Gemfile b/Gemfile index db403a8c..6a661460 100644 --- a/Gemfile +++ b/Gemfile @@ -29,7 +29,9 @@ group :development, :test do gem 'awesome_print' gem 'passenger', '~> 5.0' end + group :test do + gem 'rspec-rails' gem 'rack_session_access', '~> 0.1.1' gem 'selenium-webdriver' gem 'shoulda' diff --git a/Gemfile.lock b/Gemfile.lock index 7537625a..ecb10718 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -66,6 +66,7 @@ GEM ffi (~> 1.0, >= 1.0.11) coderay (1.1.1) concurrent-ruby (1.0.5) + diff-lcs (1.3) erubis (2.7.0) exception_notification (4.2.1) actionmailer (>= 4.0, < 6) @@ -182,6 +183,23 @@ GEM redis-store (1.2.0) redis (>= 2.2) request_store (1.3.1) + rspec-core (3.5.4) + rspec-support (~> 3.5.0) + rspec-expectations (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-mocks (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-rails (3.5.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.5.0) + rspec-expectations (~> 3.5.0) + rspec-mocks (~> 3.5.0) + rspec-support (~> 3.5.0) + rspec-support (3.5.0) ruby-saml (1.4.1) nokogiri (>= 1.5.10) rubyzip (1.2.0) @@ -256,6 +274,7 @@ DEPENDENCIES rails (= 5.0.1) rails_logger! redis-rails (= 5.0.1) + rspec-rails ruby-saml sass-rails (~> 5.0) select2-rails (= 3.5.9) diff --git a/db/migrate/20180821101102_create_links.rb b/db/migrate/20180821101102_create_links.rb index 2b354867..97727fee 100644 --- a/db/migrate/20180821101102_create_links.rb +++ b/db/migrate/20180821101102_create_links.rb @@ -1,9 +1,9 @@ class CreateLinks < ActiveRecord::Migration[5.0] def change create_table :links do |t| - t.string :alias - t.string :url - t.string :owner + t.string :alias, null: false + t.string :url, null: false + t.string :owner, null: false t.text :description t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index 91ea5381..8aec75a1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -13,9 +13,9 @@ ActiveRecord::Schema.define(version: 20180821101102) do create_table "links", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| - t.string "alias" - t.string "url" - t.string "owner" + t.string "alias", null: false + t.string "url", null: false + t.string "owner", null: false t.text "description", limit: 65535 t.datetime "created_at", null: false t.datetime "updated_at", null: false diff --git a/spec/app/models/link_spec.rb b/spec/app/models/link_spec.rb new file mode 100644 index 00000000..785dbf92 --- /dev/null +++ b/spec/app/models/link_spec.rb @@ -0,0 +1,42 @@ +describe Link do + context "validation" do + let(:link) { FactoryGirl.build(:link) } + + it "does not allow invalid urls" do + [ + "foo.net", + "www.foo.com", + "foo.biz", + "", + "a_word", + "http://a space.com", + nil + ].each do |url| + link.url = url + expect(link).not_to be_valid + end + end + + it "allows non-local urls" do + [ + "http://foo.com", + "https://foo.biz", + "http://www.foo.net", + "https://www.foo.com", + ].each do |url| + link.url = url + expect(link).to be_valid + end + end + + it "allows local urls" do + [ + "http://foo", + "https://foo", + ].each do |url| + link.url = url + expect(link).to be_valid + end + end + end +end diff --git a/spec/factories/links.rb b/spec/factories/links.rb new file mode 100644 index 00000000..613fc125 --- /dev/null +++ b/spec/factories/links.rb @@ -0,0 +1,9 @@ +FactoryGirl.define do + factory :link do + created_at Time.now + updated_at Time.now + sequence(:owner) { |i| "owner_#{i}" } + sequence(:url) { |i| "http://url_#{i}.com" } + sequence(:alias) { |i| "alias_#{i}" } + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 00000000..0dbbfa5c --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,14 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV["RAILS_ENV"] ||= 'test' +require File.expand_path("../../config/environment", __FILE__) +require 'rspec/rails' + +RSpec.configure do |config| + config.expect_with :rspec do |expectations| + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end +end diff --git a/test/controllers/.keep b/test/controllers/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/test/fixtures/.keep b/test/fixtures/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/test/helpers/.keep b/test/helpers/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/test/integration/.keep b/test/integration/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/test/mailers/.keep b/test/mailers/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/test/models/.keep b/test/models/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index 92e39b2d..00000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,10 +0,0 @@ -ENV['RAILS_ENV'] ||= 'test' -require File.expand_path('../../config/environment', __FILE__) -require 'rails/test_help' - -class ActiveSupport::TestCase - # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. - fixtures :all - - # Add more helper methods to be used by all tests here... -end From 054f174c19e857fc2317dc539784f723d29aeff7 Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Tue, 21 Aug 2018 04:16:04 -0700 Subject: [PATCH 07/17] some amendments --- config/database.yml | 8 ++++---- config/secrets.yml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/database.yml b/config/database.yml index b98d7451..ed106663 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,5 +1,5 @@ production: - database: go_links_production + database: go_links_db username: go_links_user password: "<%= Rails.application.secrets.go_links_password %>" host: "<%= Rails.application.secrets.go_links_host %>" @@ -11,7 +11,7 @@ production: reaping_frequency: 60 wait_timeout: 28800 development: - database: go_links_development + database: go_links_db_development username: go_links_user password: "<%= Rails.application.secrets.go_links_password %>" host: "<%= Rails.application.secrets.go_links_host %>" @@ -26,7 +26,7 @@ local: adapter: mysql2 username: root password: - database: go_links_local + database: go_links_db_local host: localhost encoding: utf8 reconnect: true @@ -35,6 +35,6 @@ test: username: root password: host: 127.0.0.1 - database: go_links_test + database: go_links_db_test encoding: utf8 reconnect: true diff --git a/config/secrets.yml b/config/secrets.yml index e5cd1303..aa118042 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -1,8 +1,8 @@ production: # we use production rails env in development deploys secret_key_base: 9vrWgICyWsKKlFQNwXNe69TFMbCvTLIYGChVMyCl - go_links_host: go-links-db.liveramp.net + go_links_host: apex-dbs.liveramp.net rldb_password: development: secret_key_base: uQ7mOU0Al87OZMwAp3gVhmPxf5h3CrRP2kgznkTw - go_links_host: go-links-db-dev.liveramp.net + go_links_host: apex-dbs-dev.liveramp.net rldb_password: From 96481cbfea1c423ae91d83cc92d24a8ea7709d25 Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Tue, 21 Aug 2018 04:16:12 -0700 Subject: [PATCH 08/17] fixed untracked files --- config/secrets.yml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 config/secrets.yml diff --git a/config/secrets.yml b/config/secrets.yml deleted file mode 100644 index aa118042..00000000 --- a/config/secrets.yml +++ /dev/null @@ -1,8 +0,0 @@ -production: # we use production rails env in development deploys - secret_key_base: 9vrWgICyWsKKlFQNwXNe69TFMbCvTLIYGChVMyCl - go_links_host: apex-dbs.liveramp.net - rldb_password: -development: - secret_key_base: uQ7mOU0Al87OZMwAp3gVhmPxf5h3CrRP2kgznkTw - go_links_host: apex-dbs-dev.liveramp.net - rldb_password: From dbe3944381a1668582394455f0d78b1f8a3838aa Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Tue, 21 Aug 2018 09:25:28 -0700 Subject: [PATCH 09/17] specify user in the secrets yaml so that this can work for db migrations? suggest the creation of a dev user, but not sure how that should really work here --- config/database.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config/database.yml b/config/database.yml index ed106663..fefa2c54 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,8 +1,8 @@ production: database: go_links_db - username: go_links_user + username: "<%= Rails.application.secrets.go_links_user %>" password: "<%= Rails.application.secrets.go_links_password %>" - host: "<%= Rails.application.secrets.go_links_host %>" + host: apex-dbs.liveramp.net encoding: utf8 reconnect: 'true' adapter: mysql2 @@ -11,10 +11,10 @@ production: reaping_frequency: 60 wait_timeout: 28800 development: - database: go_links_db_development - username: go_links_user - password: "<%= Rails.application.secrets.go_links_password %>" - host: "<%= Rails.application.secrets.go_links_host %>" + database: go_links_db + username: "<%= Rails.application.secrets.go_links_dev_user %>" + password: "<%= Rails.application.secrets.go_links_dev_password %>" + host: apex-dbs.liveramp.net encoding: utf8 reconnect: 'true' adapter: mysql2 From e4f3d5e63b33f922ee9b9d826091c14d644df92d Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Wed, 22 Aug 2018 01:56:51 -0700 Subject: [PATCH 10/17] make dev db local db --- config/database.yml | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/config/database.yml b/config/database.yml index fefa2c54..e33aac89 100644 --- a/config/database.yml +++ b/config/database.yml @@ -11,22 +11,10 @@ production: reaping_frequency: 60 wait_timeout: 28800 development: - database: go_links_db - username: "<%= Rails.application.secrets.go_links_dev_user %>" - password: "<%= Rails.application.secrets.go_links_dev_password %>" - host: apex-dbs.liveramp.net - encoding: utf8 - reconnect: 'true' - adapter: mysql2 - retries: 0 - pool: 5 - reaping_frequency: 60 - wait_timeout: 28800 -local: adapter: mysql2 username: root password: - database: go_links_db_local + database: go_links_local_db host: localhost encoding: utf8 reconnect: true @@ -34,7 +22,7 @@ test: adapter: mysql2 username: root password: - host: 127.0.0.1 - database: go_links_db_test + host: localhost + database: go_links_test_db encoding: utf8 reconnect: true From d229d38758cea80e1344e913728018c242156aa2 Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Wed, 22 Aug 2018 02:05:33 -0700 Subject: [PATCH 11/17] keep track of the user in code, password only is secret --- config/database.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/database.yml b/config/database.yml index e33aac89..c0a21b81 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,7 +1,7 @@ production: database: go_links_db - username: "<%= Rails.application.secrets.go_links_user %>" - password: "<%= Rails.application.secrets.go_links_password %>" + username: go_links_user + password: "<%= Rails.application.secrets.go_links_user_password %>" host: apex-dbs.liveramp.net encoding: utf8 reconnect: 'true' From 55715b517c2dd75d234412210334d3cd6453bdf2 Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Wed, 22 Aug 2018 02:06:50 -0700 Subject: [PATCH 12/17] remove fodor --- script/fodor | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 script/fodor diff --git a/script/fodor b/script/fodor deleted file mode 100644 index e7a1e0a2..00000000 --- a/script/fodor +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -hvault_path=secret/fodor/go_links/secrets.yml - -echo 'Grabbing configs for go_links [development] from hvault...' -if ! vault read -field=development $hvault_path > config/secrets.yml; then - echo '*** Failed to fetch secrets from Hashicorp Vault! ***' - echo 'You might need to auth, or re-auth, with the following command:' - echo ' vault auth -method=ldap' -fi From db7ad58e2596646114e50e610d402d0c633bb9d9 Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Wed, 22 Aug 2018 04:32:13 -0700 Subject: [PATCH 13/17] gsub _ with - before save --- app/models/link.rb | 6 ++++++ spec/app/models/link_spec.rb | 7 +++++++ spec/factories/links.rb | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/link.rb b/app/models/link.rb index b1cab814..cb1e95ec 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -1,3 +1,9 @@ class Link < ActiveRecord::Base validates :url, url: true + before_save :change_alias_underscores_to_dashes + + private + def change_alias_underscores_to_dashes + self.alias.gsub!("_", "-") + end end diff --git a/spec/app/models/link_spec.rb b/spec/app/models/link_spec.rb index 785dbf92..5a59fc46 100644 --- a/spec/app/models/link_spec.rb +++ b/spec/app/models/link_spec.rb @@ -39,4 +39,11 @@ end end end + + it "replaces underscores with dashes" do + link = FactoryGirl.build(:link, alias: "foo_bar") + link.save! + link.reload + expect(link.alias).to eq "foo-bar" + end end diff --git a/spec/factories/links.rb b/spec/factories/links.rb index 613fc125..b8e445ad 100644 --- a/spec/factories/links.rb +++ b/spec/factories/links.rb @@ -4,6 +4,6 @@ updated_at Time.now sequence(:owner) { |i| "owner_#{i}" } sequence(:url) { |i| "http://url_#{i}.com" } - sequence(:alias) { |i| "alias_#{i}" } + sequence(:alias) { |i| "alias-#{i}" } end end From a582e47498f2cd6acb5b3cc9191d8fd1b1505aba Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Wed, 22 Aug 2018 05:19:45 -0700 Subject: [PATCH 14/17] make alias unique and index it --- db/migrate/20180821101102_create_links.rb | 2 ++ db/schema.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/db/migrate/20180821101102_create_links.rb b/db/migrate/20180821101102_create_links.rb index 97727fee..31535b90 100644 --- a/db/migrate/20180821101102_create_links.rb +++ b/db/migrate/20180821101102_create_links.rb @@ -6,6 +6,8 @@ def change t.string :owner, null: false t.text :description t.timestamps + + t.index :alias, unique: true end end end diff --git a/db/schema.rb b/db/schema.rb index 8aec75a1..71eac1fd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -19,6 +19,7 @@ t.text "description", limit: 65535 t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["alias"], name: "index_links_on_alias", unique: true, using: :btree end end From c0488d64a9bf96b0e2c77e68edb56211ef609dcc Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Wed, 22 Aug 2018 05:21:03 -0700 Subject: [PATCH 15/17] add model uniqueness validation on alias --- app/models/link.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/link.rb b/app/models/link.rb index cb1e95ec..ce46edf2 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -1,5 +1,6 @@ class Link < ActiveRecord::Base validates :url, url: true + validates :alias, uniqueness: true before_save :change_alias_underscores_to_dashes private From 5e09e16b1f36a1494f42621ca88cac16b72c58db Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Thu, 23 Aug 2018 03:13:53 -0700 Subject: [PATCH 16/17] newline --- app/models/link.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/link.rb b/app/models/link.rb index ce46edf2..fbbe0456 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -4,6 +4,7 @@ class Link < ActiveRecord::Base before_save :change_alias_underscores_to_dashes private + def change_alias_underscores_to_dashes self.alias.gsub!("_", "-") end From de2b47a5c8806d77358e8095c8f2e07575aefe0b Mon Sep 17 00:00:00 2001 From: Lane Erickson Date: Thu, 23 Aug 2018 03:15:56 -0700 Subject: [PATCH 17/17] using create instead of build->save->reload --- spec/app/models/link_spec.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spec/app/models/link_spec.rb b/spec/app/models/link_spec.rb index 5a59fc46..9f2ad1d5 100644 --- a/spec/app/models/link_spec.rb +++ b/spec/app/models/link_spec.rb @@ -41,9 +41,8 @@ end it "replaces underscores with dashes" do - link = FactoryGirl.build(:link, alias: "foo_bar") - link.save! - link.reload - expect(link.alias).to eq "foo-bar" + expect( + FactoryGirl.create(:link, alias: "foo_bar").alias + ).to eq "foo-bar" end end