friendly_id-method_scopes 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/.ruby-gemspec +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +20 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +29 -0
- data/Rakefile +39 -0
- data/VERSION +1 -0
- data/coverage/.last_run.json +5 -0
- data/coverage/.resultset.json +676 -0
- data/coverage/.resultset.json.lock +0 -0
- data/friendly_id-method_scopes.gemspec +154 -0
- data/lib/friendly_id/method_scopes.rb +69 -0
- data/lib/friendly_id/method_scopes/version.rb +9 -0
- data/spec/controllers/authors_controller_spec.rb +20 -0
- data/spec/controllers/books_controller_spec.rb +20 -0
- data/spec/dummy/Rakefile +9 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/assets/stylesheets/scaffold.css +1 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/authors_controller.rb +18 -0
- data/spec/dummy/app/controllers/books_controller.rb +23 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/author.rb +12 -0
- data/spec/dummy/app/models/book.rb +16 -0
- data/spec/dummy/app/models/role.rb +10 -0
- data/spec/dummy/app/views/authors/index.html.haml +5 -0
- data/spec/dummy/app/views/authors/show.html.haml +5 -0
- data/spec/dummy/app/views/books/index.html.haml +5 -0
- data/spec/dummy/app/views/books/show.html.haml +5 -0
- data/spec/dummy/app/views/layouts/application.html.haml +10 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +44 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/rolify.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +6 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/migrate/20150621221655_create_books.rb +10 -0
- data/spec/dummy/db/migrate/20150621221732_create_authors.rb +10 -0
- data/spec/dummy/db/migrate/20150622182214_rolify_create_roles.rb +19 -0
- data/spec/dummy/db/schema.rb +48 -0
- data/spec/dummy/db/seeds.rb +0 -0
- data/spec/dummy/db/seeds/authors.seeds.rb +2 -0
- data/spec/dummy/db/seeds/books.seeds.rb +9 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/author.rb +6 -0
- data/spec/factories/book.rb +15 -0
- data/spec/models/author_spec.rb +11 -0
- data/spec/models/book_spec.rb +15 -0
- data/spec/rails_helper.rb +45 -0
- data/spec/routing/authors_routing_spec.rb +15 -0
- data/spec/routing/books_routing_spec.rb +15 -0
- data/spec/spec_helper.rb +94 -0
- data/spec/support/authors.rb +4 -0
- data/spec/support/books_with_authors.rb +7 -0
- metadata +306 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
|
6
|
+
# Make sure the secret is at least 30 characters and all random,
|
7
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
+
# You can use `rake secret` to generate a secure secret key.
|
9
|
+
|
10
|
+
# Make sure the secrets in this file are kept private
|
11
|
+
# if you're sharing your code publicly.
|
12
|
+
|
13
|
+
development:
|
14
|
+
secret_key_base: 8bec2b9266c0e33fbd7886ce708d2639a7dc79bed4d35cd44976e10e47b08d4db98bfbeb41d6820a5332baf9ac8a34dbd6c84ddefa90940a4ce16b5e4e6e1b25
|
15
|
+
|
16
|
+
test:
|
17
|
+
secret_key_base: 464dad9c71f0f4a49173465c056d28b20b8853e5b755da9b31b6f11327af1e60169b3e42fb11ba64764c225ae399a1ca70b380a6b3abe3f4a090dcf370073dec
|
18
|
+
|
19
|
+
# Do not keep production secrets in the repository,
|
20
|
+
# instead read values from the environment.
|
21
|
+
production:
|
22
|
+
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class RolifyCreateRoles < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table(:roles) do |t|
|
4
|
+
t.string :name
|
5
|
+
t.references :resource, :polymorphic => true
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
create_table(:authors_roles, :id => false) do |t|
|
11
|
+
t.references :author
|
12
|
+
t.references :role
|
13
|
+
end
|
14
|
+
|
15
|
+
add_index(:roles, :name)
|
16
|
+
add_index(:roles, [ :name, :resource_type, :resource_id ])
|
17
|
+
add_index(:authors_roles, [ :author_id, :role_id ])
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended that you check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(version: 20150622182214) do
|
15
|
+
|
16
|
+
create_table "authors", force: :cascade do |t|
|
17
|
+
t.string "full_name"
|
18
|
+
t.string "slug"
|
19
|
+
t.datetime "created_at", null: false
|
20
|
+
t.datetime "updated_at", null: false
|
21
|
+
end
|
22
|
+
|
23
|
+
create_table "authors_roles", id: false, force: :cascade do |t|
|
24
|
+
t.integer "author_id"
|
25
|
+
t.integer "role_id"
|
26
|
+
end
|
27
|
+
|
28
|
+
add_index "authors_roles", ["author_id", "role_id"], name: "index_authors_roles_on_author_id_and_role_id"
|
29
|
+
|
30
|
+
create_table "books", force: :cascade do |t|
|
31
|
+
t.string "title"
|
32
|
+
t.string "slug"
|
33
|
+
t.datetime "created_at", null: false
|
34
|
+
t.datetime "updated_at", null: false
|
35
|
+
end
|
36
|
+
|
37
|
+
create_table "roles", force: :cascade do |t|
|
38
|
+
t.string "name"
|
39
|
+
t.integer "resource_id"
|
40
|
+
t.string "resource_type"
|
41
|
+
t.datetime "created_at"
|
42
|
+
t.datetime "updated_at"
|
43
|
+
end
|
44
|
+
|
45
|
+
add_index "roles", ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id"
|
46
|
+
add_index "roles", ["name"], name: "index_roles_on_name"
|
47
|
+
|
48
|
+
end
|
File without changes
|
@@ -0,0 +1,9 @@
|
|
1
|
+
after :authors do
|
2
|
+
first_author = Author.friendly.find('first-author')
|
3
|
+
second_author = Author.friendly.find('second-author')
|
4
|
+
|
5
|
+
FactoryGirl.create(:book, title: 'Book A', author: first_author)
|
6
|
+
FactoryGirl.create(:book, title: 'Book B', author: first_author)
|
7
|
+
FactoryGirl.create(:book, title: 'Book C', author: second_author)
|
8
|
+
FactoryGirl.create(:book, title: 'Book B', author: second_author)
|
9
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :book do
|
3
|
+
title { Faker::Company.catch_phrase }
|
4
|
+
transient do
|
5
|
+
author { Author.order("RANDOM()").first }
|
6
|
+
end
|
7
|
+
# the after(:create) yields two values; the user instance itself and the
|
8
|
+
# evaluator, which stores all values from the factory, including transient
|
9
|
+
# attributes; `create_list`'s second argument is the number of records
|
10
|
+
# to create and we make sure the user is associated properly to the post
|
11
|
+
after(:create) do |book, evaluator|
|
12
|
+
evaluator.author.add_role(:author, book)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe Book do
|
4
|
+
include_context 'books with authors'
|
5
|
+
|
6
|
+
describe 'generates proper slug for first item' do
|
7
|
+
subject { book_b_first.to_param }
|
8
|
+
it { should eq 'book-b' }
|
9
|
+
end
|
10
|
+
describe 'generates proper slug for same slug in another scope' do
|
11
|
+
subject { book_b_second.to_param }
|
12
|
+
it { should eq 'book-b' }
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV['RAILS_ENV'] ||= 'test'
|
3
|
+
require File.expand_path('../dummy/config/environment', __FILE__)
|
4
|
+
# Prevent database truncation if the environment is production
|
5
|
+
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
6
|
+
require 'spec_helper'
|
7
|
+
require 'rspec/rails'
|
8
|
+
require 'shoulda/matchers'
|
9
|
+
require 'database_cleaner'
|
10
|
+
require 'rake'
|
11
|
+
# Add additional requires below this line. Rails is not loaded until this point!
|
12
|
+
|
13
|
+
# Requires supporting ruby files with custom matchers and macros, etc, in
|
14
|
+
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
15
|
+
# run as spec files by default. This means that files in spec/support that end
|
16
|
+
# in _spec.rb will both be required and run as specs, causing the specs to be
|
17
|
+
# run twice. It is recommended that you do not name files matching this glob to
|
18
|
+
# end with _spec.rb. You can configure this pattern with the --pattern
|
19
|
+
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
20
|
+
#
|
21
|
+
# The following line is provided for convenience purposes. It has the downside
|
22
|
+
# of increasing the boot-up time by auto-requiring all files in the support
|
23
|
+
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
24
|
+
# require only the support files necessary.
|
25
|
+
#
|
26
|
+
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
27
|
+
|
28
|
+
# Checks for pending migrations before tests are run.
|
29
|
+
# If you are not using ActiveRecord, you can remove this line.
|
30
|
+
ActiveRecord::Migration.maintain_test_schema!
|
31
|
+
|
32
|
+
RSpec.configure do |config|
|
33
|
+
config.before(:suite) do
|
34
|
+
DatabaseCleaner.strategy = :transaction
|
35
|
+
DatabaseCleaner.clean_with(:truncation)
|
36
|
+
Dummy::Application.load_tasks
|
37
|
+
Rake::Task['db:seed'].invoke # loading seeds
|
38
|
+
end
|
39
|
+
config.around(:each) do |example|
|
40
|
+
DatabaseCleaner.cleaning do
|
41
|
+
example.run
|
42
|
+
end
|
43
|
+
end
|
44
|
+
config.infer_spec_type_from_file_location!
|
45
|
+
end
|