friendly_id_datamapper 3.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,84 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+ require 'friendly_id/datamapper_adapter/tasks'
3
+
4
+ class TasksTest < Test::Unit::TestCase
5
+
6
+ def teardown
7
+ ENV["MODEL"] = nil
8
+ [City, District, Post, Slug].each do |clazz|
9
+ clazz.all.destroy!
10
+ end
11
+ end
12
+
13
+ test "should make slugs" do
14
+ City.create :name => "Nairobi"
15
+ City.create :name => "Buenos Aires"
16
+ Slug.all.destroy!
17
+ ENV["MODEL"] = "City"
18
+ FriendlyId::TaskRunner.new.make_slugs
19
+ assert_equal 2, Slug.count
20
+ end
21
+
22
+ test "should admit lower case, plural model names" do
23
+ ENV["MODEL"] = "cities"
24
+ assert_equal City, FriendlyId::TaskRunner.new.klass
25
+ end
26
+
27
+ test "make_slugs should raise error if no model given" do
28
+ assert_raise(RuntimeError) { FriendlyId::TaskRunner.new.make_slugs }
29
+ end
30
+
31
+ test "make_slugs should raise error if class doesn't use FriendlyId" do
32
+ ENV["MODEL"] = "String"
33
+ assert_raise(RuntimeError) { FriendlyId::TaskRunner.new.make_slugs }
34
+ end
35
+
36
+ test"delete_slugs delete only slugs for the specified model" do
37
+ Post.create :name => "Slugs Considered Harmful"
38
+ City.create :name => "Buenos Aires"
39
+ ENV["MODEL"] = "city"
40
+ FriendlyId::TaskRunner.new.delete_slugs
41
+ assert_equal 1, Slug.count
42
+ end
43
+
44
+ test "delete_slugs should set the cached_slug column to NULL" do
45
+ ENV["MODEL"] = "district"
46
+ District.create :name => "Garment"
47
+ FriendlyId::TaskRunner.new.delete_slugs
48
+ assert_nil District.first.cached_slug
49
+ end
50
+
51
+
52
+ test "delete_old_slugs should delete slugs older than 45 days by default" do
53
+ set_up_old_slugs
54
+ FriendlyId::TaskRunner.new.delete_old_slugs
55
+ assert_equal 2, Slug.count
56
+ end
57
+
58
+ test "delete_old_slugs should respect the days argument" do
59
+ set_up_old_slugs
60
+ ENV["DAYS"] = "100"
61
+ FriendlyId::TaskRunner.new.delete_old_slugs
62
+ assert_equal 3, Slug.count
63
+ end
64
+
65
+ test "delete_old_slugs should respect the class argument" do
66
+ set_up_old_slugs
67
+ ENV["MODEL"] = "post"
68
+ FriendlyId::TaskRunner.new.delete_old_slugs
69
+ assert_equal 3, Slug.count
70
+ end
71
+
72
+ private
73
+
74
+ def set_up_old_slugs
75
+ Post.create :name => "Slugs Considered Harmful"
76
+ city = City.create :name => "Buenos Aires"
77
+ City.repository(:default).adapter.execute "UPDATE slugs SET created_at = '%s' WHERE id = %d" % [
78
+ 45.days.ago.strftime("%Y-%m-%d"), city.slug.id
79
+ ]
80
+ city.update :name => "Ciudad de Buenos Aires"
81
+ assert_equal 3, Slug.count
82
+ end
83
+
84
+ end
@@ -0,0 +1,37 @@
1
+ # Use Bundler (preferred)
2
+ begin
3
+ require File.expand_path('../../.bundle/environment', __FILE__)
4
+ rescue LoadError
5
+ require 'rubygems'
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ require "friendly_id"
11
+ require "friendly_id/test"
12
+ require "logger"
13
+ require "test/unit"
14
+ require "mocha"
15
+
16
+ require 'forwardable'
17
+
18
+ require 'dm-core'
19
+ require 'dm-validations'
20
+ require 'dm-migrations'
21
+ # NOTE: dm-active_model is not a runtime requirement, as we implement
22
+ # #to_param for models. It is a testing requirement to ensure that our
23
+ # #to_param implementation overrides the default dm-active_model impl.
24
+ require 'dm-active_model'
25
+
26
+ DataMapper::Logger.new('dm.log', :debug)
27
+ DataMapper.setup(:default, 'sqlite3::memory:')
28
+
29
+ $LOAD_PATH << './lib'
30
+
31
+ require 'friendly_id_datamapper'
32
+ require File.expand_path('../core', __FILE__)
33
+ require File.expand_path('../slugged', __FILE__)
34
+
35
+ require File.expand_path('../support/models', __FILE__)
36
+ DataMapper.finalize
37
+ DataMapper.auto_migrate!
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: friendly_id_datamapper
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 3
7
+ - 1
8
+ - 0
9
+ - beta1
10
+ version: 3.1.0.beta1
11
+ platform: ruby
12
+ authors:
13
+ - Norman Clarke
14
+ - Alex Coles
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-09-13 00:00:00 +02:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: friendly_id
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ segments:
31
+ - 3
32
+ - 1
33
+ - 0
34
+ version: 3.1.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: dm-core
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 1
47
+ - 0
48
+ - 0
49
+ version: 1.0.0
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: dm-validations
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 1
62
+ - 0
63
+ - 0
64
+ version: 1.0.0
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: dm-transactions
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 1
77
+ - 0
78
+ - 0
79
+ version: 1.0.0
80
+ type: :runtime
81
+ version_requirements: *id004
82
+ description: An adapter for using DataMapper::Resource with FriendlyId.
83
+ email:
84
+ - norman@njclarke.com
85
+ - alex@alexbcoles.com
86
+ executables: []
87
+
88
+ extensions: []
89
+
90
+ extra_rdoc_files: []
91
+
92
+ files:
93
+ - lib/friendly_id/datamapper_adapter/configuration.rb
94
+ - lib/friendly_id/datamapper_adapter/simple_model.rb
95
+ - lib/friendly_id/datamapper_adapter/slug.rb
96
+ - lib/friendly_id/datamapper_adapter/slugged_model.rb
97
+ - lib/friendly_id/datamapper_adapter/tasks.rb
98
+ - lib/friendly_id/datamapper_adapter/version.rb
99
+ - lib/friendly_id_datamapper.rb
100
+ - ChangeLog.md
101
+ - README.md
102
+ - MIT-LICENSE
103
+ - Rakefile
104
+ - test/basic_slugged_model_test.rb
105
+ - test/cached_slug_test.rb
106
+ - test/core.rb
107
+ - test/custom_normalizer_test.rb
108
+ - test/custom_table_name_test.rb
109
+ - test/scoped_model_test.rb
110
+ - test/simple_test.rb
111
+ - test/slug_test.rb
112
+ - test/slugged.rb
113
+ - test/slugged_status_test.rb
114
+ - test/sti_test.rb
115
+ - test/support/models.rb
116
+ - test/tasks_test.rb
117
+ - test/test_helper.rb
118
+ has_rdoc: true
119
+ homepage: http://github.com/myabc/friendly_id_datamapper
120
+ licenses: []
121
+
122
+ post_install_message:
123
+ rdoc_options: []
124
+
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ">"
139
+ - !ruby/object:Gem::Version
140
+ segments:
141
+ - 1
142
+ - 3
143
+ - 1
144
+ version: 1.3.1
145
+ requirements: []
146
+
147
+ rubyforge_project: "[none]"
148
+ rubygems_version: 1.3.7
149
+ signing_key:
150
+ specification_version: 3
151
+ summary: A DataMapper adapter for FriendlyId
152
+ test_files:
153
+ - test/basic_slugged_model_test.rb
154
+ - test/cached_slug_test.rb
155
+ - test/custom_normalizer_test.rb
156
+ - test/custom_table_name_test.rb
157
+ - test/scoped_model_test.rb
158
+ - test/simple_test.rb
159
+ - test/slug_test.rb
160
+ - test/slugged_status_test.rb
161
+ - test/sti_test.rb
162
+ - test/tasks_test.rb