norman-friendly_id 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,36 +0,0 @@
1
- module FriendlyId
2
-
3
- # A Shoulda[http://www.thoughtbot.com/projects/shoulda/] macros for testing
4
- # models using FriendlyId.
5
- module ShouldaMacros
6
-
7
- # Ensure that a model is using FriendlyId.
8
- def self.should_have_friendly_id(column, options = {})
9
-
10
- options.assert_valid_keys(:use_slug)
11
- klass = self.model_class
12
-
13
- should "have friendly id for #{method}" do
14
- assert_respond_to klass, :friendly_id_options,
15
- "#{klass} does not respond to friendly_id_options"
16
- assert_equal column, klass.friendly_id_options[:method]
17
- end
18
-
19
- if options[:use_slug]
20
- should "include/extend friendly_id's sluggable modules" do
21
- assert klass.extended_by.include?(FriendlyId::SluggableClassMethods),
22
- "#{klass} does not extend FriendlyId::SluggableClassMethods"
23
- assert klass.include?(FriendlyId::SluggableInstanceMethods),
24
- "#{klass} not include FriendlyId::SluggableInstanceMethods"
25
- end
26
- else
27
- should "include/extend friendly_id's non-sluggable modules" do
28
- assert klass.extended_by.include?(FriendlyId::NonSluggableClassMethods),
29
- "#{klass} does not extend FriendlyId::NonSluggableClassMethods"
30
- assert klass.include?(FriendlyId::NonSluggableInstanceMethods),
31
- "#{klass} not include FriendlyId::NonSluggableInstanceMethods"
32
- end
33
- end
34
- end
35
- end
36
- end
data/test/database.yml DELETED
@@ -1,3 +0,0 @@
1
- sqlite3:
2
- adapter: sqlite3
3
- database: ":memory:"
@@ -1,4 +0,0 @@
1
- argentina:
2
- name: Argentina
3
- usa:
4
- name: USA
@@ -1,7 +0,0 @@
1
- john_smith:
2
- name: John Smith
3
- country: argentina
4
-
5
- john_smith2:
6
- name: John Smith
7
- country: usa
@@ -1,3 +0,0 @@
1
- class Post < ActiveRecord::Base
2
- has_friendly_id :name, :use_slug => true, :reserved => ['new', 'edit']
3
- end
@@ -1,23 +0,0 @@
1
- without_slug:
2
- name: Without a slug
3
- content: Content without a slug
4
-
5
- with_one_slug:
6
- name: With one slug
7
- content: Content with one slug
8
-
9
- with_two_slugs:
10
- name: With two slugs
11
- content: Content with two slugs
12
-
13
- common_title:
14
- name: Common Title
15
- content: A post with a very common title
16
-
17
- common_title2:
18
- name: Common Title
19
- content: A second post with a very common title
20
-
21
- john_smith:
22
- name: John Smith
23
- content: Should allow for identical slug names between sluggable types
@@ -1,53 +0,0 @@
1
- post_with_same_friendly_id_as_person:
2
- name: john-smith
3
- sluggable: john_smith (Post)
4
-
5
- person_with_same_friendly_id_as_post:
6
- name: john-smith
7
- sluggable: john_smith (Person)
8
-
9
- one:
10
- name: with-one-slug
11
- sluggable: with_one_slug
12
- sluggable_type: Post
13
- sequence: 1
14
-
15
- two_old:
16
- name: with-two-slugs
17
- sluggable: with_two_slugs (Post)
18
- sequence: 1
19
-
20
- two_new:
21
- name: with-two-slugs-new
22
- sluggable: with_two_slugs (Post)
23
- sequence: 1
24
-
25
- common_title:
26
- name: common-title
27
- sluggable: common_title (Post)
28
- sequence: 1
29
-
30
- common_title2:
31
- name: common-title
32
- sluggable: common_title2 (Post)
33
- sequence: 2
34
-
35
- john_smith:
36
- name: john-smith
37
- sluggable: john_smith (Person)
38
- sequence: 1
39
- scope: argentina
40
-
41
- john_smith2:
42
- name: john-smith
43
- sluggable: john_smith2 (Person)
44
- sequence: 1
45
- scope: usa
46
-
47
- argentina:
48
- name: argentina
49
- sluggable: argentina (Country)
50
-
51
- usa:
52
- name: usa
53
- sluggable: usa (Country)
@@ -1,7 +0,0 @@
1
- joe:
2
- login: joe
3
- email: joe@example.org
4
-
5
- jane:
6
- login: jane
7
- email: jane@example.org
File without changes
@@ -1,109 +0,0 @@
1
- # Don't change this file!
2
- # Configure your app in config/environment.rb and config/environments/*.rb
3
-
4
- RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
-
6
- module Rails
7
- class << self
8
- def boot!
9
- unless booted?
10
- preinitialize
11
- pick_boot.run
12
- end
13
- end
14
-
15
- def booted?
16
- defined? Rails::Initializer
17
- end
18
-
19
- def pick_boot
20
- (vendor_rails? ? VendorBoot : GemBoot).new
21
- end
22
-
23
- def vendor_rails?
24
- File.exist?("#{RAILS_ROOT}/vendor/rails")
25
- end
26
-
27
- def preinitialize
28
- load(preinitializer_path) if File.exist?(preinitializer_path)
29
- end
30
-
31
- def preinitializer_path
32
- "#{RAILS_ROOT}/config/preinitializer.rb"
33
- end
34
- end
35
-
36
- class Boot
37
- def run
38
- load_initializer
39
- Rails::Initializer.run(:set_load_path)
40
- end
41
- end
42
-
43
- class VendorBoot < Boot
44
- def load_initializer
45
- require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
- Rails::Initializer.run(:install_gem_spec_stubs)
47
- end
48
- end
49
-
50
- class GemBoot < Boot
51
- def load_initializer
52
- self.class.load_rubygems
53
- load_rails_gem
54
- require 'initializer'
55
- end
56
-
57
- def load_rails_gem
58
- if version = self.class.gem_version
59
- gem 'rails', version
60
- else
61
- gem 'rails'
62
- end
63
- rescue Gem::LoadError => load_error
64
- $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
65
- exit 1
66
- end
67
-
68
- class << self
69
- def rubygems_version
70
- Gem::RubyGemsVersion rescue nil
71
- end
72
-
73
- def gem_version
74
- if defined? RAILS_GEM_VERSION
75
- RAILS_GEM_VERSION
76
- elsif ENV.include?('RAILS_GEM_VERSION')
77
- ENV['RAILS_GEM_VERSION']
78
- else
79
- parse_gem_version(read_environment_rb)
80
- end
81
- end
82
-
83
- def load_rubygems
84
- require 'rubygems'
85
- min_version = '1.3.1'
86
- unless rubygems_version >= min_version
87
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
88
- exit 1
89
- end
90
-
91
- rescue LoadError
92
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
93
- exit 1
94
- end
95
-
96
- def parse_gem_version(text)
97
- $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
98
- end
99
-
100
- private
101
- def read_environment_rb
102
- File.read("#{RAILS_ROOT}/config/environment.rb")
103
- end
104
- end
105
- end
106
- end
107
-
108
- # All that for this:
109
- Rails.boot!
@@ -1,3 +0,0 @@
1
- test:
2
- adapter: sqlite3
3
- database: ":memory:"
@@ -1,7 +0,0 @@
1
- if ENV['RAILS_VERSION']
2
- RAILS_GEM_VERSION = ENV['RAILS_VERSION']
3
- end
4
- require File.join(File.dirname(__FILE__), 'boot')
5
- Rails::Initializer.run
6
- ActiveRecord::Base.colorize_logging = false
7
- require File.dirname(__FILE__) + '/../../../../init.rb'
@@ -1,6 +0,0 @@
1
- config.cache_classes = true
2
- config.whiny_nils = true
3
- config.action_controller.consider_all_requests_local = true
4
- config.action_controller.perform_caching = false
5
- config.action_controller.allow_forgery_protection = false
6
- config.action_mailer.delivery_method = :test
File without changes
@@ -1,192 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class SluggableTest < Test::Unit::TestCase
4
-
5
- fixtures :posts, :slugs
6
-
7
- def setup
8
- Post.friendly_id_options[:max_length] = FriendlyId::ClassMethods::DEFAULT_FRIENDLY_ID_OPTIONS[:max_length]
9
- Post.friendly_id_options[:strip_non_ascii] = false
10
- Post.friendly_id_options[:strip_diacritics] = false
11
- end
12
-
13
- def test_should_allow_for_identical_slug_names_between_sluggable_types
14
- assert !Post.find(slugs(:post_with_same_friendly_id_as_person).name).has_better_id?
15
- end
16
-
17
- def test_class_should_have_friendly_id_options
18
- assert_not_nil Post.friendly_id_options
19
- end
20
-
21
- def test_should_generate_slug_text
22
- @post = Post.new(:name => "Test post", :content => "Test content")
23
- assert_equal "test-post", @post.slug_text
24
- end
25
-
26
- def test_should_save_slug_when_creating
27
- @post = Post.create(:name => "Test post", :content => "Test content")
28
- assert @post.slug
29
- end
30
-
31
- def test_to_param_should_always_return_a_string
32
- assert_equal String, posts(:without_slug).to_param.class
33
- assert_equal String, posts(:with_one_slug).to_param.class
34
- end
35
-
36
- def test_finder_options_are_not_ignored
37
- assert_raises ActiveRecord::RecordNotFound do
38
- Post.find(slugs(:one).name, :conditions => "1 = 2")
39
- end
40
- end
41
-
42
- def test_should_still_be_able_to_find_record_by_id
43
- post = Post.create!(:name => "New post")
44
- Post.create!(:name => "#{post.id.to_s} and some text")
45
- assert_equal post, Post.find(post.id)
46
- end
47
-
48
-
49
- def test_should_not_be_found_using_friendly_id_by_default
50
- @post = Post.new
51
- assert !@post.found_using_friendly_id?
52
- assert @post.found_using_numeric_id?
53
- end
54
-
55
- def test_should_be_using_friendly_id_when_find_arg_is_an_array
56
- @posts = Post.find([posts(:with_one_slug).friendly_id, posts(:with_two_slugs).friendly_id])
57
- assert @posts.all? { |post| post.found_using_friendly_id? }
58
- end
59
-
60
- def test_raises_active_record_not_found_when_not_all_records_found
61
- assert_raises(ActiveRecord::RecordNotFound) do
62
- Post.find([posts(:with_one_slug).slug.name, 'non-existant-slug-record'])
63
- end
64
- end
65
-
66
- def test_should_indicate_if_it_was_found_using_numeric_id
67
- @post = Post.find(posts(:with_two_slugs).id)
68
- assert @post.found_using_numeric_id?
69
- end
70
-
71
- def test_post_should_indicate_if_it_was_found_using_friendly_id
72
- @post = Post.find(posts(:with_two_slugs).slug.name)
73
- assert @post.found_using_friendly_id?
74
- end
75
-
76
- def test_post_should_indicate_if_it_was_found_using_outdated_friendly_id
77
- @post = Post.find(posts(:with_two_slugs).slugs.last.name)
78
- assert @post.found_using_outdated_friendly_id?
79
- end
80
-
81
- def test_should_indicate_there_is_a_better_id_if_found_by_numeric_id
82
- @post = Post.find(posts(:with_one_slug).id)
83
- assert @post.has_better_id?
84
- end
85
-
86
- def test_should_indicate_there_is_a_better_id_if_found_by_outdated_friendly_id
87
- @post = Post.find(posts(:with_two_slugs).slugs.last.name)
88
- assert @post.has_better_id?
89
- end
90
-
91
- def test_slug_should_always_be_the_most_recent
92
- @post = Post.find(posts(:with_two_slugs).slug.name)
93
- assert !@post.has_better_id?
94
- assert slugs(:two_new).name, @post.slug.name
95
- end
96
-
97
- def test_should_strip_diactics_from_slug_if_configured_to_do_so
98
- Post.friendly_id_options[:strip_diacritics] = true
99
- @post = Post.new(:name => "¡FELIZ AÑO!")
100
- # Happy anus to you too
101
- assert_equal "feliz-ano", @post.slug_text
102
- end
103
-
104
- def test_should_not_strip_diactics_from_slug_unless_configured_to_do_so
105
- @post = Post.new(:name => "¡FELIZ AÑO!")
106
- assert_equal "feliz-año", @post.slug_text
107
- end
108
-
109
- def test_should_convert_to_ascii
110
- Post.friendly_id_options[:strip_non_ascii] = true
111
- @post = Post.new(:name => "17” cômpütér mõnitor")
112
- assert_equal '17-computer-monitor', @post.slug_text
113
- end
114
-
115
- def test_should_not_make_new_slug_unless_friendly_id_method_has_changed
116
- posts(:with_one_slug).content = "Edited content"
117
- posts(:with_one_slug).save!
118
- assert_equal 1, posts(:with_one_slug).slugs.size
119
- end
120
-
121
- def test_post_should_make_new_slug_if_friendly_id_method_is_changed
122
- posts(:with_one_slug).name = "Edited name"
123
- posts(:with_one_slug).save!
124
- assert_equal 2, posts(:with_one_slug).slugs.size
125
- end
126
-
127
- def test_should_increment_sequence_for_duplicate_slugs
128
- @post = Post.create!(:name => slugs(:one).name, :content => "stuff")
129
- assert_equal 2, @post.slug.sequence
130
- end
131
-
132
- def test_friendly_id_should_contain_sequence_unless_its_1
133
- @post = Post.create!(:name => slugs(:one).name, :content => "stuff")
134
- assert_equal "#{slugs(:one).name}--2", @post.friendly_id
135
- end
136
-
137
- def test_should_truncate_slugs_longer_than_maxlength
138
- Post.friendly_id_options[:max_length] = 10
139
- @post = Post.new(:name => "x" * 11, :content => "Test content")
140
- assert @post.slug_text.length <= Post.friendly_id_options[:max_length]
141
- end
142
-
143
- def test_should_ensure_truncated_slugs_that_collide_have_different_sequences
144
- Post.friendly_id_options[:max_length] = 2
145
- p = Post.create!(:name => "aaa")
146
- q = Post.create!(:name => "aaab")
147
- assert_not_equal p.friendly_id, q.friendly_id
148
- assert_equal p.slug.name, q.slug.name
149
- assert_not_equal p.slug.sequence, q.slug.sequence
150
- end
151
-
152
- def test_should_be_able_to_rename_back_to_old_friendly_id
153
- p = Post.create!(:name => "value")
154
- assert_equal "value", p.friendly_id
155
- p.name = "different value"
156
- p.save!
157
- p.reload
158
- assert_equal "different-value", p.friendly_id
159
- p.name = "value"
160
- assert p.save!
161
- p.reload
162
- assert_equal "value", p.friendly_id
163
- end
164
-
165
- def test_should_raise_error_if_friendly_id_is_blank
166
- assert_raises(FriendlyId::SlugGenerationError) do
167
- Post.create(:name => nil)
168
- end
169
- end
170
-
171
- def test_should_raise_error_if_normalized_friendly_id_becomes_blank
172
- assert_raises(FriendlyId::SlugGenerationError) do
173
- post = Post.create!(:name => "-.-")
174
- end
175
- end
176
-
177
- def test_should_raise_error_if_slug_text_is_reserved
178
- assert_raises(FriendlyId::SlugGenerationError) do
179
- Post.create(:name => "new")
180
- end
181
- end
182
-
183
- def test_should_allow_eager_loading_of_slugs
184
- assert_nothing_raised do
185
- Post.find(slugs(:one).name, :include => :slugs)
186
- end
187
- assert_nothing_raised do
188
- Post.find([slugs(:one).name, slugs(:two_new).name], :include => :slugs)
189
- end
190
- end
191
-
192
- end
File without changes
File without changes
File without changes