teambox-permalink_fu 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 796145ed6da4b5645dc2f373f6065845b66b61cc
4
+ data.tar.gz: ab564f64f5762cc27999b1ae48c3610a96be6f7b
5
+ SHA512:
6
+ metadata.gz: 290a0087418cf8650c04fb4c3ff61898ed7ff175ccc9fdacd02235d74ebe47cb9806c51e09f5ce9785bcf205a7aa5ea40f08cc14cb059db219849d86061e7bcf
7
+ data.tar.gz: 5c56804d1dd12fb808bb849e6f1406d71036eafb68f17f9643f7258ff8db45326959b2c9ab24767aa23bb887ef2df083e4dc1f0b08bbc2ad82844359fe5a86de
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
+ Gemfile.lock
data/Rakefile CHANGED
@@ -1,2 +1,14 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
8
+
9
+ desc 'Test the permalink_fu plugin.'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
@@ -1,5 +1,5 @@
1
1
  ---
2
- - "\z"
2
+ - "\0"
3
3
  - "\x01"
4
4
  - "\x02"
5
5
  - "\x03"
@@ -126,7 +126,7 @@
126
126
  - '|'
127
127
  - '}'
128
128
  - '~'
129
- - 
129
+ - '\x7f'
130
130
  - ''
131
131
  - ''
132
132
  - ''
@@ -254,4 +254,4 @@
254
254
  - u
255
255
  - y
256
256
  - th
257
- - y
257
+ - y
@@ -1,5 +1,4 @@
1
1
  require 'yaml'
2
- require 'iconv'
3
2
 
4
3
  module PermalinkFu
5
4
  def has_permalink(attr_names = [], permalink_field = nil, options = {})
@@ -12,21 +11,26 @@ module PermalinkFu
12
11
  self.permalink_field = (permalink_field || 'permalink').to_s
13
12
  self.permalink_options = {:unique => true, :min_length => 1}.update(options)
14
13
  end
15
-
14
+
16
15
  include InstanceMethods
17
16
  end
18
17
 
19
18
  class << self
20
19
  # This method does the actual permalink escaping.
21
20
  def escape(str, klass = nil)
22
- s = ClassMethods.decode(str)#.force_encoding("UTF-8")
23
- s = Iconv.iconv('ascii//ignore//translit', 'utf-8', s).to_s
21
+ if Gem::Version.new("#{RUBY_VERSION}") < Gem::Version.new("1.9")
22
+ require 'iconv'
23
+ s = ClassMethods.decode(str)#.force_encoding("UTF-8")
24
+ s = Iconv.iconv('ascii//ignore//translit', 'utf-8', s).to_s
25
+ else
26
+ s = ClassMethods.decode(str).encode("ascii")
27
+ end
24
28
  s.gsub!(/[^\w_ \-]+/i, '') # Remove unwanted chars.
25
29
  s.gsub!(/[ \-]+/i, '-') # No more than one of the separator in a row.
26
30
  s.gsub!(/^\-|\-$/i, '') # Remove leading/trailing separator.
27
31
  s.downcase!
28
- s = "#{klass}-#{s}" if klass && Integer(s) rescue s
29
- s.size == 0 ? ClassMethods.random_permalink : s
32
+ s = "#{klass}-#{s}" if klass && s.match(/\A\d+\z/)
33
+ s = s.size < klass.classify.constantize.permalink_options[:min_length] ? ClassMethods.random_permalink : s
30
34
  end
31
35
  end
32
36
 
@@ -36,7 +40,7 @@ module PermalinkFu
36
40
  CODEPOINTS = Hash.new { |h, k|
37
41
  h[k] = YAML::load_file(File.join(File.dirname(__FILE__), "data", "#{k}.yml"))
38
42
  }
39
-
43
+
40
44
  class << self
41
45
  def decode(string)
42
46
  string.gsub(/[^\x00-\x7f]/u) do |codepoint|
@@ -47,12 +51,12 @@ module PermalinkFu
47
51
  end
48
52
  end
49
53
  end
50
-
54
+
51
55
  def random_permalink
52
56
  rand(Time.now.to_i**2).to_s(36)
53
57
  end
54
58
  end
55
-
59
+
56
60
  def self.setup_permalink_fu_on(base)
57
61
  base.extend self
58
62
  class << base
@@ -78,7 +82,7 @@ module PermalinkFu
78
82
  if (value = define_attribute_methods_without_permalinks) && self.permalink_field
79
83
  class_eval <<-EOV
80
84
  def #{self.permalink_field}=(new_value);
81
- write_attribute(:#{self.permalink_field}, new_value.blank? ? '' : PermalinkFu.escape(new_value, self.class.to_s.downcase));
85
+ write_attribute(:#{self.permalink_field}, new_value.blank? ? '' : PermalinkFu.escape(new_value.to_s, self.class.to_s));
82
86
  end
83
87
  EOV
84
88
  end
@@ -127,7 +131,7 @@ module PermalinkFu
127
131
  end
128
132
  end
129
133
  while self.class.exists?(conditions)
130
- suffix = "-#{counter += 1}"
134
+ suffix = "-".concat(SecureRandom.hex(3))
131
135
  conditions[1] = "#{base[0..limit-suffix.size-1]}#{suffix}"
132
136
  send("#{self.class.permalink_field}=", conditions[1])
133
137
  end
@@ -1,18 +1,19 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = "teambox-permalink_fu"
6
- s.version = "1.0.2"
5
+ s.name = 'teambox-permalink_fu'
6
+ s.version = '1.0.4'
7
7
  s.platform = Gem::Platform::RUBY
8
- s.authors = ["Gonçalo Silva", "Charles Barbier"]
9
- s.email = ["goncalossilva@gmail.com", "unixcharles@gmail.com"]
10
- s.homepage = "http://rubygems.org/gems/teambox-permalink_fu"
11
- s.summary = %q{Fork of permalink_fu used at Teambox}
12
- s.description = %q{Same functionality as the original one, except now it doesn't accept numerical permalinks and is safer with unicode characters.}
8
+ s.authors = ["Gonçalo Silva", 'Charles Barbier']
9
+ s.email = ['goncalossilva@gmail.com', 'unixcharles@gmail.com']
10
+ s.homepage = 'http://rubygems.org/gems/teambox-permalink_fu'
11
+ s.summary = 'Fork of permalink_fu used at Teambox'
12
+ s.description = 'Same functionality as the original one, except now it ' \
13
+ "doesn't accept numerical permalinks and is safer with" \
14
+ 'unicode characters.'
13
15
 
14
16
  s.files = `git ls-files`.split("\n")
15
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
- s.require_paths = ["lib"]
17
+ s.test_files = `git ls-files -- {test}/*`.split("\n")
18
+ s.require_paths = ['lib']
18
19
  end
@@ -0,0 +1,130 @@
1
+ class ClassModel < ActiveRecord::Base
2
+ has_permalink :title
3
+ end
4
+
5
+ class SubClassHasPermalinkModel < ClassModel
6
+ has_permalink [:title, :extra]
7
+ end
8
+
9
+ class SubClassNoPermalinkModel < ClassModel
10
+ end
11
+
12
+ class MockModel < ClassModel
13
+ def self.exists?(conditions)
14
+ if conditions[1] == 'foo' || conditions[1] == 'bar' ||
15
+ (conditions[1] == 'bar-2' && conditions[2] != 2)
16
+ true
17
+ else
18
+ false
19
+ end
20
+ end
21
+
22
+ has_permalink :title
23
+ end
24
+
25
+ class PermalinkChangeableMockModel < ClassModel
26
+ def self.exists?(conditions)
27
+ if conditions[1] == 'foo'
28
+ true
29
+ else
30
+ false
31
+ end
32
+ end
33
+
34
+ has_permalink :title
35
+
36
+ def permalink_changed?
37
+ @permalink_changed
38
+ end
39
+
40
+ def permalink_will_change!
41
+ @permalink_changed = true
42
+ end
43
+ end
44
+
45
+ class CommonMockModel < ClassModel
46
+ def self.exists?(conditions)
47
+ false # oh noes
48
+ end
49
+
50
+ has_permalink :title, :unique => false
51
+ end
52
+
53
+ class ScopedModel < ClassModel
54
+ def self.exists?(conditions)
55
+ if conditions[1] == 'foo' && conditions[2] != 5
56
+ true
57
+ else
58
+ false
59
+ end
60
+ end
61
+
62
+ has_permalink :title, :scope => :foo
63
+ end
64
+
65
+ class ScopedModelForNilScope < ClassModel
66
+ def self.exists?(conditions)
67
+ (conditions[0] == 'permalink = ? and foo IS NULL') ? (conditions[1] == 'ack') : false
68
+ end
69
+
70
+ has_permalink :title, :scope => :foo
71
+ end
72
+
73
+ class OverrideModel < ClassModel
74
+ has_permalink :title
75
+
76
+ def permalink
77
+ 'not the permalink'
78
+ end
79
+ end
80
+
81
+ class ChangedWithoutUpdateModel < ClassModel
82
+ has_permalink :title
83
+ def title_changed?; true; end
84
+ end
85
+
86
+ class ChangedWithUpdateModel < ClassModel
87
+ has_permalink :title, :update => true
88
+ def title_changed?; true; end
89
+ end
90
+
91
+ class NoChangeModel < ClassModel
92
+ has_permalink :title, :update => true
93
+ def title_changed?; false; end
94
+ end
95
+
96
+ class IfProcConditionModel < ClassModel
97
+ has_permalink :title, :if => Proc.new { |obj| false }
98
+ end
99
+
100
+ class IfMethodConditionModel < ClassModel
101
+ has_permalink :title, :if => :false_method
102
+
103
+ def false_method; false; end
104
+ end
105
+
106
+ class IfStringConditionModel < ClassModel
107
+ has_permalink :title, :if => 'false'
108
+ end
109
+
110
+ class UnlessProcConditionModel < ClassModel
111
+ has_permalink :title, :unless => Proc.new { |obj| false }
112
+ end
113
+
114
+ class UnlessMethodConditionModel < ClassModel
115
+ has_permalink :title, :unless => :false_method
116
+
117
+ def false_method; false; end
118
+ end
119
+
120
+ class UnlessStringConditionModel < ClassModel
121
+ has_permalink :title, :unless => 'false'
122
+ end
123
+
124
+ class MockModelExtra < ClassModel
125
+ has_permalink [:title, :extra]
126
+ end
127
+
128
+ class MinLength < ClassModel
129
+ has_permalink :title, :min_length => 5
130
+ end
@@ -1,10 +1,31 @@
1
1
  # encoding: UTF-8
2
2
 
3
- # Load the plugin's test_helper (Rails 2.x needs the path)
4
- begin
5
- require File.dirname(__FILE__) + '/test_helper.rb'
6
- rescue LoadError
7
- require 'test_helper'
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+ require 'active_record'
6
+ require 'permalink_fu'
7
+ require './test/models'
8
+
9
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
10
+
11
+ def setup_db
12
+ silence_stream(STDOUT) do
13
+ ActiveRecord::Schema.define(:version => 1) do
14
+ create_table :class_models do |t|
15
+ t.integer :id
16
+ t.string :title
17
+ t.string :permalink
18
+ t.string :extra
19
+ t.string :foo
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ def teardown_db
26
+ ActiveRecord::Base.connection.tables.each do |table|
27
+ ActiveRecord::Base.connection.drop_table(table)
28
+ end
8
29
  end
9
30
 
10
31
  class PermalinkFuTest < Test::Unit::TestCase
@@ -18,14 +39,12 @@ class PermalinkFuTest < Test::Unit::TestCase
18
39
 
19
40
  @@extra = { 'some-)()()-ExtRa!/// .data==?> to \/\/test' => 'some-extra-data-to-test' }
20
41
 
21
- def test_basemodel
22
- @m = BaseModel.new
23
- assert @m.valid?
24
- assert_equal @m.id, nil
25
- assert_equal @m.title, nil
26
- assert_equal @m.permalink, nil
27
- assert_equal @m.extra, nil
28
- assert_equal @m.foo, nil
42
+ def setup
43
+ setup_db
44
+ end
45
+
46
+ def teardown
47
+ teardown_db
29
48
  end
30
49
 
31
50
  def test_set_new_permalink_attributes_on_sub_class
@@ -34,14 +53,14 @@ class PermalinkFuTest < Test::Unit::TestCase
34
53
  @m.extra = 'bar'
35
54
  assert @m.valid?
36
55
  assert_equal @m.permalink, 'foo'
37
-
56
+
38
57
  @m = SubClassHasPermalinkModel.new
39
58
  @m.title = 'foo'
40
59
  @m.extra = 'bar'
41
60
  assert @m.valid?
42
61
  assert_equal @m.permalink, 'foo-bar'
43
62
  end
44
-
63
+
45
64
  def test_should_not_inherit_permalink_attributes
46
65
  @m = SubClassNoPermalinkModel.new
47
66
  @m.title = 'foo'
@@ -49,12 +68,6 @@ class PermalinkFuTest < Test::Unit::TestCase
49
68
  assert_equal @m.permalink, nil
50
69
  end
51
70
 
52
- def test_should_escape_permalinks
53
- @@samples.each do |from, to|
54
- assert_equal to, PermalinkFu.escape(from)
55
- end
56
- end
57
-
58
71
  def test_should_escape_activerecord_model
59
72
  @m = MockModel.new
60
73
  @@samples.each do |from, to|
@@ -63,7 +76,7 @@ class PermalinkFuTest < Test::Unit::TestCase
63
76
  assert_equal to, @m.permalink
64
77
  end
65
78
  end
66
-
79
+
67
80
  def test_should_escape_activerecord_model_with_existing_permalink
68
81
  @m = MockModel.new
69
82
  @@samples.each do |from, to|
@@ -72,8 +85,9 @@ class PermalinkFuTest < Test::Unit::TestCase
72
85
  assert_equal to, @m.permalink
73
86
  end
74
87
  end
75
-
88
+
76
89
  def test_multiple_attribute_permalink
90
+
77
91
  @m = MockModelExtra.new
78
92
  @@samples.each do |from, to|
79
93
  @@extra.each do |from_extra, to_extra|
@@ -88,33 +102,33 @@ class PermalinkFuTest < Test::Unit::TestCase
88
102
  @m = MockModel.new
89
103
  @m.title = 'foo'
90
104
  assert @m.valid?
91
- assert_equal 'foo-2', @m.permalink
92
-
105
+ assert_match /foo\-[0-9a-z]+/, @m.permalink
106
+
93
107
  @m.title = 'bar'
94
108
  @m.permalink = nil
95
109
  assert @m.valid?
96
- assert_equal 'bar-3', @m.permalink
110
+ assert_match /bar\-[0-9a-z]+/, @m.permalink
97
111
  end
98
-
112
+
99
113
  def test_should_create_unique_permalink_when_assigned_directly
100
114
  @m = MockModel.new
101
115
  @m.permalink = 'foo'
102
116
  assert @m.valid?
103
- assert_equal 'foo-2', @m.permalink
104
-
117
+ assert_match /foo\-[0-9a-z]+/, @m.permalink
118
+
105
119
  # should always check itself for uniqueness when not respond_to?(:permalink_changed?)
106
120
  @m.permalink = 'bar'
107
121
  assert @m.valid?
108
- assert_equal 'bar-3', @m.permalink
122
+ assert_match /bar\-[0-9a-z]+/, @m.permalink
109
123
  end
110
-
124
+
111
125
  def test_should_common_permalink_if_unique_is_false
112
126
  @m = CommonMockModel.new
113
127
  @m.permalink = 'foo'
114
128
  assert @m.valid?
115
129
  assert_equal 'foo', @m.permalink
116
130
  end
117
-
131
+
118
132
  def test_should_not_check_itself_for_unique_permalink_if_unchanged
119
133
  @m = MockModel.new
120
134
  @m.id = 2
@@ -131,7 +145,7 @@ class PermalinkFuTest < Test::Unit::TestCase
131
145
  @m.permalink_will_change!
132
146
  @m.permalink = 'foo'
133
147
  assert @m.valid?
134
- assert_equal 'foo-2', @m.permalink
148
+ assert_match /foo\-[0-9a-z]+/, @m.permalink
135
149
  end
136
150
 
137
151
  def test_should_not_check_itself_for_unique_permalink_if_permalink_field_not_changed
@@ -140,19 +154,19 @@ class PermalinkFuTest < Test::Unit::TestCase
140
154
  assert @m.valid?
141
155
  assert_equal 'foo', @m.permalink
142
156
  end
143
-
157
+
144
158
  def test_should_create_unique_scoped_permalink
145
159
  @m = ScopedModel.new
146
160
  @m.permalink = 'foo'
147
161
  assert @m.valid?
148
- assert_equal 'foo-2', @m.permalink
149
-
162
+ assert_match /foo\-[0-9a-z]+/, @m.permalink
163
+
150
164
  @m.foo = 5
151
165
  @m.permalink = 'foo'
152
166
  assert @m.valid?
153
167
  assert_equal 'foo', @m.permalink
154
168
  end
155
-
169
+
156
170
  def test_should_limit_permalink
157
171
  @old = MockModel.columns_hash['permalink'].instance_variable_get(:@limit)
158
172
  MockModel.columns_hash['permalink'].instance_variable_set(:@limit, 2)
@@ -163,73 +177,73 @@ class PermalinkFuTest < Test::Unit::TestCase
163
177
  ensure
164
178
  MockModel.columns_hash['permalink'].instance_variable_set(:@limit, @old)
165
179
  end
166
-
180
+
167
181
  def test_should_limit_unique_permalink
168
182
  @old = MockModel.columns_hash['permalink'].instance_variable_get(:@limit)
169
183
  MockModel.columns_hash['permalink'].instance_variable_set(:@limit, 3)
170
184
  @m = MockModel.new
171
185
  @m.title = 'foo'
172
186
  assert @m.valid?
173
- assert_equal 'f-2', @m.permalink
187
+ assert_match /[0-9a-z]+/, @m.permalink
174
188
  ensure
175
189
  MockModel.columns_hash['permalink'].instance_variable_set(:@limit, @old)
176
190
  end
177
-
191
+
178
192
  def test_should_abide_by_if_proc_condition
179
193
  @m = IfProcConditionModel.new
180
194
  @m.title = 'dont make me a permalink'
181
195
  assert @m.valid?
182
196
  assert_nil @m.permalink
183
197
  end
184
-
198
+
185
199
  def test_should_abide_by_if_method_condition
186
200
  @m = IfMethodConditionModel.new
187
201
  @m.title = 'dont make me a permalink'
188
202
  assert @m.valid?
189
203
  assert_nil @m.permalink
190
204
  end
191
-
205
+
192
206
  def test_should_abide_by_if_string_condition
193
207
  @m = IfStringConditionModel.new
194
208
  @m.title = 'dont make me a permalink'
195
209
  assert @m.valid?
196
210
  assert_nil @m.permalink
197
211
  end
198
-
212
+
199
213
  def test_should_abide_by_unless_proc_condition
200
214
  @m = UnlessProcConditionModel.new
201
215
  @m.title = 'make me a permalink'
202
216
  assert @m.valid?
203
217
  assert_not_nil @m.permalink
204
218
  end
205
-
219
+
206
220
  def test_should_abide_by_unless_method_condition
207
221
  @m = UnlessMethodConditionModel.new
208
222
  @m.title = 'make me a permalink'
209
223
  assert @m.valid?
210
224
  assert_not_nil @m.permalink
211
225
  end
212
-
226
+
213
227
  def test_should_abide_by_unless_string_condition
214
228
  @m = UnlessStringConditionModel.new
215
229
  @m.title = 'make me a permalink'
216
230
  assert @m.valid?
217
231
  assert_not_nil @m.permalink
218
232
  end
219
-
233
+
220
234
  def test_should_allow_override_of_permalink_method
221
235
  @m = OverrideModel.new
222
236
  @m[:permalink] = 'the permalink'
223
237
  assert_not_equal @m.permalink, @m[:permalink]
224
238
  end
225
-
239
+
226
240
  def test_should_create_permalink_from_attribute_not_attribute_accessor
227
241
  @m = OverrideModel.new
228
242
  @m.title = 'the permalink'
229
243
  assert @m.valid?
230
244
  assert_equal 'the-permalink', @m[:permalink]
231
245
  end
232
-
246
+
233
247
  def test_should_not_update_permalink_unless_field_changed
234
248
  @m = NoChangeModel.new
235
249
  @m.title = 'the permalink'
@@ -237,7 +251,7 @@ class PermalinkFuTest < Test::Unit::TestCase
237
251
  assert @m.valid?
238
252
  assert_equal 'unchanged', @m[:permalink]
239
253
  end
240
-
254
+
241
255
  def test_should_not_update_permalink_without_update_set_even_if_field_changed
242
256
  @m = ChangedWithoutUpdateModel.new
243
257
  @m.title = 'the permalink'
@@ -245,7 +259,7 @@ class PermalinkFuTest < Test::Unit::TestCase
245
259
  assert @m.valid?
246
260
  assert_equal 'unchanged', @m[:permalink]
247
261
  end
248
-
262
+
249
263
  def test_should_update_permalink_if_changed_method_does_not_exist
250
264
  @m = OverrideModel.new
251
265
  @m.title = 'the permalink'
@@ -312,165 +326,27 @@ class PermalinkFuTest < Test::Unit::TestCase
312
326
  assert @m.valid?
313
327
  assert_equal "new-title", @m[:permalink]
314
328
  end
315
-
329
+
316
330
  def test_should_work_correctly_for_scoped_fields_with_nil_value
317
331
  s1 = ScopedModelForNilScope.new
318
332
  s1.title = 'ack'
319
333
  s1.foo = 3
320
334
  assert s1.valid?
321
335
  assert_equal 'ack', s1.permalink
322
-
336
+
337
+
323
338
  s2 = ScopedModelForNilScope.new
324
339
  s2.title = 'ack'
325
340
  s2.foo = nil
326
341
  assert s2.valid?
327
- assert_equal 'ack-2', s2.permalink
328
- end
329
- end
330
-
331
- class BaseModel < ActiveRecord::Base
332
- cattr_accessor :columns
333
- @@columns ||= []
334
-
335
- def self.column(name, sql_type = nil, default = nil, null = true)
336
- columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type, null)
337
- end
338
-
339
- def self.exists?(*args)
340
- false
341
- end
342
-
343
- column :id, 'int(11)'
344
- column :title, 'varchar(100)'
345
- column :permalink, 'varchar(100)'
346
- column :extra, 'varchar(100)'
347
- column :foo, 'varchar(100)'
348
-
349
- end
350
-
351
- class ClassModel < BaseModel
352
- has_permalink :title
353
- end
354
-
355
- class SubClassHasPermalinkModel < ClassModel
356
- has_permalink [:title, :extra]
357
- end
358
-
359
- class SubClassNoPermalinkModel < ClassModel
360
- end
361
-
362
- class MockModel < BaseModel
363
- def self.exists?(conditions)
364
- if conditions[1] == 'foo' || conditions[1] == 'bar' ||
365
- (conditions[1] == 'bar-2' && conditions[2] != 2)
366
- true
367
- else
368
- false
369
- end
370
- end
371
-
372
- has_permalink :title
373
- end
374
-
375
- class PermalinkChangeableMockModel < BaseModel
376
- def self.exists?(conditions)
377
- if conditions[1] == 'foo'
378
- true
379
- else
380
- false
381
- end
382
- end
383
-
384
- has_permalink :title
385
-
386
- def permalink_changed?
387
- @permalink_changed
388
- end
389
-
390
- def permalink_will_change!
391
- @permalink_changed = true
392
- end
393
- end
394
-
395
- class CommonMockModel < BaseModel
396
- def self.exists?(conditions)
397
- false # oh noes
398
- end
399
-
400
- has_permalink :title, :unique => false
401
- end
402
-
403
- class ScopedModel < BaseModel
404
- def self.exists?(conditions)
405
- if conditions[1] == 'foo' && conditions[2] != 5
406
- true
407
- else
408
- false
409
- end
410
- end
411
-
412
- has_permalink :title, :scope => :foo
413
- end
414
-
415
- class ScopedModelForNilScope < BaseModel
416
- def self.exists?(conditions)
417
- (conditions[0] == 'permalink = ? and foo IS NULL') ? (conditions[1] == 'ack') : false
342
+ assert_match /ack-[0-9a-z]+/, s2.permalink
418
343
  end
419
344
 
420
- has_permalink :title, :scope => :foo
421
- end
422
-
423
- class OverrideModel < BaseModel
424
- has_permalink :title
425
-
426
- def permalink
427
- 'not the permalink'
345
+ def test_permalink_is_randomly_created_when_min_length_is_set
346
+ a = MinLength.create(:title => "MinL")
347
+ assert a.permalink.size.eql?(12)
348
+ a = MinLength.create(:title => "MinLe")
349
+ assert_equal "minle", a.permalink
428
350
  end
429
- end
430
-
431
- class ChangedWithoutUpdateModel < BaseModel
432
- has_permalink :title
433
- def title_changed?; true; end
434
- end
435
-
436
- class ChangedWithUpdateModel < BaseModel
437
- has_permalink :title, :update => true
438
- def title_changed?; true; end
439
- end
440
-
441
- class NoChangeModel < BaseModel
442
- has_permalink :title, :update => true
443
- def title_changed?; false; end
444
- end
445
-
446
- class IfProcConditionModel < BaseModel
447
- has_permalink :title, :if => Proc.new { |obj| false }
448
- end
449
-
450
- class IfMethodConditionModel < BaseModel
451
- has_permalink :title, :if => :false_method
452
-
453
- def false_method; false; end
454
- end
455
-
456
- class IfStringConditionModel < BaseModel
457
- has_permalink :title, :if => 'false'
458
- end
459
-
460
- class UnlessProcConditionModel < BaseModel
461
- has_permalink :title, :unless => Proc.new { |obj| false }
462
- end
463
-
464
- class UnlessMethodConditionModel < BaseModel
465
- has_permalink :title, :unless => :false_method
466
-
467
- def false_method; false; end
468
- end
469
-
470
- class UnlessStringConditionModel < BaseModel
471
- has_permalink :title, :unless => 'false'
472
- end
473
351
 
474
- class MockModelExtra < BaseModel
475
- has_permalink [:title, :extra]
476
352
  end
metadata CHANGED
@@ -1,37 +1,26 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: teambox-permalink_fu
3
- version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 0
9
- - 2
10
- version: 1.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
11
5
  platform: ruby
12
- authors:
13
- - "Gon\xC3\xA7alo Silva"
6
+ authors:
7
+ - Gonçalo Silva
14
8
  - Charles Barbier
15
9
  autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
-
19
- date: 2011-09-20 00:00:00 +02:00
20
- default_executable:
12
+ date: 2016-04-04 00:00:00.000000000 Z
21
13
  dependencies: []
22
-
23
- description: Same functionality as the original one, except now it doesn't accept numerical permalinks and is safer with unicode characters.
24
- email:
14
+ description: Same functionality as the original one, except now it doesn't accept
15
+ numerical permalinks and is safer withunicode characters.
16
+ email:
25
17
  - goncalossilva@gmail.com
26
18
  - unixcharles@gmail.com
27
19
  executables: []
28
-
29
20
  extensions: []
30
-
31
21
  extra_rdoc_files: []
32
-
33
- files:
34
- - .gitignore
22
+ files:
23
+ - ".gitignore"
35
24
  - Gemfile
36
25
  - README.markdown
37
26
  - Rakefile
@@ -218,42 +207,29 @@ files:
218
207
  - lib/data/xff.yml
219
208
  - lib/permalink_fu.rb
220
209
  - teambox-permalink_fu.gemspec
210
+ - test/models.rb
221
211
  - test/permalink_fu_test.rb
222
- - test/test_helper.rb
223
- has_rdoc: true
224
212
  homepage: http://rubygems.org/gems/teambox-permalink_fu
225
213
  licenses: []
226
-
214
+ metadata: {}
227
215
  post_install_message:
228
216
  rdoc_options: []
229
-
230
- require_paths:
217
+ require_paths:
231
218
  - lib
232
- required_ruby_version: !ruby/object:Gem::Requirement
233
- none: false
234
- requirements:
219
+ required_ruby_version: !ruby/object:Gem::Requirement
220
+ requirements:
235
221
  - - ">="
236
- - !ruby/object:Gem::Version
237
- hash: 3
238
- segments:
239
- - 0
240
- version: "0"
241
- required_rubygems_version: !ruby/object:Gem::Requirement
242
- none: false
243
- requirements:
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ required_rubygems_version: !ruby/object:Gem::Requirement
225
+ requirements:
244
226
  - - ">="
245
- - !ruby/object:Gem::Version
246
- hash: 3
247
- segments:
248
- - 0
249
- version: "0"
227
+ - !ruby/object:Gem::Version
228
+ version: '0'
250
229
  requirements: []
251
-
252
230
  rubyforge_project:
253
- rubygems_version: 1.3.7
231
+ rubygems_version: 2.6.2
254
232
  signing_key:
255
- specification_version: 3
233
+ specification_version: 4
256
234
  summary: Fork of permalink_fu used at Teambox
257
- test_files:
258
- - test/permalink_fu_test.rb
259
- - test/test_helper.rb
235
+ test_files: []
@@ -1,13 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'active_record'
4
-
5
- begin
6
- require 'ruby-debug'
7
- Debugger.start
8
- rescue LoadError
9
- # no ruby debugger
10
- end
11
-
12
- $:.unshift "#{File.dirname(__FILE__)}/../lib/"
13
- require 'permalink_fu'