permalink 1.2.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/FUNDING.yml +3 -0
- data/.gitignore +3 -1
- data/.rubocop.yml +13 -0
- data/.travis.yml +7 -0
- data/Gemfile +3 -1
- data/README.md +118 -0
- data/Rakefile +14 -4
- data/lib/permalink.rb +38 -8
- data/lib/permalink/active_record.rb +127 -0
- data/lib/permalink/normalizations/contraction.rb +11 -0
- data/lib/permalink/normalizations/downcase.rb +11 -0
- data/lib/permalink/normalizations/leading_trailing_dashes.rb +11 -0
- data/lib/permalink/normalizations/multiple_dashes.rb +11 -0
- data/lib/permalink/normalizations/non_alphanumeric.rb +12 -0
- data/lib/permalink/normalizations/transliteration.rb +14 -0
- data/lib/permalink/version.rb +4 -2
- data/permalink.gemspec +15 -13
- data/test/permalink/active_record_test.rb +175 -0
- data/test/permalink/normalizations_test.rb +48 -0
- data/test/permalink/permalink_test.rb +22 -0
- data/test/support/post.rb +5 -0
- data/test/support/schema.rb +11 -0
- data/test/support/user.rb +5 -0
- data/test/test_helper.rb +17 -0
- metadata +94 -106
- data/.rspec +0 -1
- data/Gemfile.lock +0 -79
- data/README.markdown +0 -79
- data/lib/permalink/orm/active_record.rb +0 -26
- data/lib/permalink/orm/base.rb +0 -83
- data/lib/permalink/orm/mongo_mapper.rb +0 -28
- data/lib/permalink/orm/mongoid.rb +0 -24
- data/lib/permalink/string_ext.rb +0 -12
- data/spec/permalink/active_record_spec.rb +0 -13
- data/spec/permalink/mongo_mapper_spec.rb +0 -13
- data/spec/permalink/mongoid_spec.rb +0 -13
- data/spec/permalink/string_spec.rb +0 -23
- data/spec/spec_helper.rb +0 -24
- data/spec/support/article.rb +0 -4
- data/spec/support/page.rb +0 -5
- data/spec/support/post.rb +0 -2
- data/spec/support/schema.rb +0 -5
- data/spec/support/shared.rb +0 -95
data/spec/support/post.rb
DELETED
data/spec/support/schema.rb
DELETED
data/spec/support/shared.rb
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
shared_examples_for "orm" do
|
2
|
-
before do
|
3
|
-
model.delete_all
|
4
|
-
model.permalink :title
|
5
|
-
end
|
6
|
-
|
7
|
-
it "should respond to options" do
|
8
|
-
model.should respond_to(:permalink_options)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should use default options" do
|
12
|
-
model.permalink :title
|
13
|
-
record = model.create(:title => "Some nice post")
|
14
|
-
record.permalink.should == "some-nice-post"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should use custom attribute" do
|
18
|
-
model.permalink :title, :to => :slug
|
19
|
-
record = model.create(:title => "Some nice post")
|
20
|
-
record.slug.should == "some-nice-post"
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should set permalink before_save" do
|
24
|
-
record = model.new(:title => "Some nice post")
|
25
|
-
record.permalink.should be_nil
|
26
|
-
record.valid?
|
27
|
-
record.permalink.should == "some-nice-post"
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should create unique permalinks" do
|
31
|
-
model.permalink :title, :unique => true
|
32
|
-
|
33
|
-
record = model.create(:title => "Some nice post")
|
34
|
-
record.permalink.should == "some-nice-post"
|
35
|
-
|
36
|
-
record = model.create(:title => "Some nice post")
|
37
|
-
record.permalink.should == "some-nice-post-2"
|
38
|
-
|
39
|
-
record = model.create(:title => "Some nice post")
|
40
|
-
record.permalink.should == "some-nice-post-3"
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should return to_param for unique permalink" do
|
44
|
-
model.permalink :title, :to_param => :permalink, :unique => true
|
45
|
-
|
46
|
-
record = model.create(:title => "Ruby")
|
47
|
-
record.to_param.should == "ruby"
|
48
|
-
|
49
|
-
record = model.create(:title => "Ruby")
|
50
|
-
record.to_param.should == "ruby-2"
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should override to_param with custom fields" do
|
54
|
-
model.permalink :title, :to => :slug, :to_param => [:slug, :id, "page"]
|
55
|
-
|
56
|
-
record = model.create(:title => "Some nice post")
|
57
|
-
record.to_param.should == "some-nice-post-#{record.id}-page"
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should ignore blank attributes from to_param" do
|
61
|
-
model.permalink :title, :to_param => [:id, " ", nil, "\t", :permalink]
|
62
|
-
|
63
|
-
record = model.create(:title => "Some nice post")
|
64
|
-
record.to_param.should == "#{record.id}-some-nice-post"
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should set permalink if permalink is blank" do
|
68
|
-
record = model.create(:title => "Some nice post", :permalink => " ")
|
69
|
-
record.permalink.should == "some-nice-post"
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should keep defined permalink" do
|
73
|
-
record = model.create(:title => "Some nice post", :permalink => "awesome-post")
|
74
|
-
record.permalink.should == "awesome-post"
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should create unique permalinks for number-ended titles" do
|
78
|
-
model.permalink :title, :unique => true
|
79
|
-
|
80
|
-
record = model.create(:title => "Rails 3")
|
81
|
-
record.permalink.should == "rails-3"
|
82
|
-
|
83
|
-
record = model.create(:title => "Rails 3")
|
84
|
-
record.permalink.should == "rails-3-2"
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should force permalink" do
|
88
|
-
model.permalink :title, :force => true
|
89
|
-
|
90
|
-
record = model.create(:title => "Some nice post")
|
91
|
-
record.update_attributes :title => "Awesome post"
|
92
|
-
|
93
|
-
record.permalink.should == "awesome-post"
|
94
|
-
end
|
95
|
-
end
|