isa-friendly_id_datamapper 3.2.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,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: isa-friendly_id_datamapper
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 3
7
+ - 2
8
+ - 0
9
+ - beta1
10
+ version: 3.2.0.beta1
11
+ platform: ruby
12
+ authors:
13
+ - Norman Clarke
14
+ - Alex Coles
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-06-12 00:00:00 +08: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
+ - 2
33
+ version: "3.2"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: dm-core
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ segments:
45
+ - 1
46
+ - 1
47
+ version: "1.1"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: dm-validations
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 1
60
+ - 1
61
+ version: "1.1"
62
+ type: :runtime
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: dm-transactions
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 1
74
+ - 1
75
+ version: "1.1"
76
+ type: :runtime
77
+ version_requirements: *id004
78
+ description: An adapter for using DataMapper::Resource with FriendlyId.
79
+ email:
80
+ - norman@njclarke.com
81
+ - alex@alexbcoles.com
82
+ executables: []
83
+
84
+ extensions: []
85
+
86
+ extra_rdoc_files: []
87
+
88
+ files:
89
+ - lib/friendly_id/datamapper_adapter/simple_model.rb
90
+ - lib/friendly_id/datamapper_adapter/tasks.rb
91
+ - lib/friendly_id/datamapper_adapter/version.rb
92
+ - lib/friendly_id/datamapper_adapter/slugged_model.rb
93
+ - lib/friendly_id/datamapper_adapter/configuration.rb
94
+ - lib/friendly_id/datamapper_adapter/slug.rb
95
+ - lib/friendly_id_datamapper.rb
96
+ - README.md
97
+ - ChangeLog.md
98
+ - MIT-LICENSE
99
+ - Rakefile
100
+ - test/core.rb
101
+ - test/scoped_model_test.rb
102
+ - test/test_helper.rb
103
+ - test/slug_test.rb
104
+ - test/custom_table_name_test.rb
105
+ - test/sti_test.rb
106
+ - test/support/models.rb
107
+ - test/simple_test.rb
108
+ - test/custom_normalizer_test.rb
109
+ - test/tasks_test.rb
110
+ - test/slugged.rb
111
+ - test/basic_slugged_model_test.rb
112
+ - test/slugged_status_test.rb
113
+ - test/cached_slug_test.rb
114
+ has_rdoc: true
115
+ homepage: http://github.com/myabc/friendly_id_datamapper
116
+ licenses: []
117
+
118
+ post_install_message:
119
+ rdoc_options: []
120
+
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ">"
135
+ - !ruby/object:Gem::Version
136
+ segments:
137
+ - 1
138
+ - 3
139
+ - 1
140
+ version: 1.3.1
141
+ requirements: []
142
+
143
+ rubyforge_project: "[none]"
144
+ rubygems_version: 1.3.7
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: A DataMapper adapter for FriendlyId
148
+ test_files:
149
+ - test/scoped_model_test.rb
150
+ - test/slug_test.rb
151
+ - test/custom_table_name_test.rb
152
+ - test/sti_test.rb
153
+ - test/simple_test.rb
154
+ - test/custom_normalizer_test.rb
155
+ - test/tasks_test.rb
156
+ - test/basic_slugged_model_test.rb
157
+ - test/slugged_status_test.rb
158
+ - test/cached_slug_test.rb