Skip to content

Commit

Permalink
Merge pull request sass#14 from RailsRepos/ACT-437
Browse files Browse the repository at this point in the history
Act-437: add model and migrations for go_links links
  • Loading branch information
Lane Erickson authored and GitHub Enterprise committed Aug 23, 2018
2 parents bb795e5 + de2b47a commit e9f96ee
Show file tree
Hide file tree
Showing 22 changed files with 183 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ tmp/
node_modules/
*bundle.js
npm-debug.log
config/secrets.yml
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ gem 'sass-rails', '~> 5.0'
gem 'httparty', '0.13.7'
gem 'exception_notification', '~> 4.1'
gem 'rails_logger', git: '[email protected]:RailsRepos/rails_logger.git'
gem 'mysql2', '~> 0.4'
gem 'validate_url', '~> 1.0'

group :development, :test do
gem 'capybara'
Expand All @@ -27,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'
Expand Down
29 changes: 27 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -117,6 +118,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)
Expand Down Expand Up @@ -162,7 +164,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)
Expand All @@ -181,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)
Expand Down Expand Up @@ -219,6 +238,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)
Expand All @@ -243,6 +265,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
Expand All @@ -251,13 +274,15 @@ 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)
selenium-webdriver
shoulda
sprockets-rails (~> 2.0)
uglifier (= 2.7.2)
validate_url (~> 1.0)

BUNDLED WITH
1.14.6
1.16.0
Empty file removed app/models/.keep
Empty file.
Empty file removed app/models/concerns/.keep
Empty file.
11 changes: 11 additions & 0 deletions app/models/link.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Link < ActiveRecord::Base
validates :url, url: true
validates :alias, uniqueness: true
before_save :change_alias_underscores_to_dashes

private

def change_alias_underscores_to_dashes
self.alias.gsub!("_", "-")
end
end
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 28 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
production:
database: go_links_db
username: go_links_user
password: "<%= Rails.application.secrets.go_links_user_password %>"
host: apex-dbs.liveramp.net
encoding: utf8
reconnect: 'true'
adapter: mysql2
retries: 0
pool: 5
reaping_frequency: 60
wait_timeout: 28800
development:
adapter: mysql2
username: root
password:
database: go_links_local_db
host: localhost
encoding: utf8
reconnect: true
test:
adapter: mysql2
username: root
password:
host: localhost
database: go_links_test_db
encoding: utf8
reconnect: true
22 changes: 0 additions & 22 deletions config/secrets.yml

This file was deleted.

13 changes: 13 additions & 0 deletions db/migrate/20180821101102_create_links.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateLinks < ActiveRecord::Migration[5.0]
def change
create_table :links do |t|
t.string :alias, null: false
t.string :url, null: false
t.string :owner, null: false
t.text :description
t.timestamps

t.index :alias, unique: true
end
end
end
25 changes: 25 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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", 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
t.index ["alias"], name: "index_links_on_alias", unique: true, using: :btree
end

end
48 changes: 48 additions & 0 deletions spec/app/models/link_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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

it "replaces underscores with dashes" do
expect(
FactoryGirl.create(:link, alias: "foo_bar").alias
).to eq "foo-bar"
end
end
9 changes: 9 additions & 0 deletions spec/factories/links.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Empty file removed test/controllers/.keep
Empty file.
Empty file removed test/fixtures/.keep
Empty file.
Empty file removed test/helpers/.keep
Empty file.
Empty file removed test/integration/.keep
Empty file.
Empty file removed test/mailers/.keep
Empty file.
Empty file removed test/models/.keep
Empty file.
10 changes: 0 additions & 10 deletions test/test_helper.rb

This file was deleted.

0 comments on commit e9f96ee

Please sign in to comment.