pseudocephalopod 0.3.1 → 0.3.2

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.
@@ -1,19 +0,0 @@
1
- require 'reversible_data'
2
-
3
- ReversibleData.in_memory!
4
-
5
- # Define models here.
6
-
7
- ReversibleData.add :slugs do |t|
8
- t.string :scope
9
- t.string :slug
10
- t.integer :record_id
11
- t.datetime :created_at
12
- end
13
-
14
- ReversibleData.add :users do |u|
15
- u.string :name
16
- u.string :address
17
- u.string :cached_slug
18
- u.timestamps
19
- end
@@ -1,27 +0,0 @@
1
- require 'helper'
2
-
3
- class PseudocephalopodTest < Test::Unit::TestCase
4
-
5
- class SlugScopeTest
6
- cattr_accessor :slug_scope_key
7
- self.slug_scope_key = "my-test-scope"
8
- end
9
-
10
- should 'return the correct counter versions' do
11
- assert_equal 'awesome', Pseudocephalopod.with_counter('awesome')
12
- assert_equal 'awesome', Pseudocephalopod.with_counter('awesome', 0)
13
- assert_equal 'awesome', Pseudocephalopod.with_counter('awesome', -1)
14
- assert_equal 'awesome--2', Pseudocephalopod.with_counter('awesome', 2)
15
- assert_equal 'awesome--100', Pseudocephalopod.with_counter('awesome', 100)
16
- end
17
-
18
- should 'correct allow you to slug scope keys' do
19
- assert_equal "my-test-scope", Pseudocephalopod.key_for_scope(SlugScopeTest)
20
- assert_equal "my-test-scope", Pseudocephalopod.key_for_scope(SlugScopeTest.new)
21
- assert_equal "my-test-scope", Pseudocephalopod.key_for_scope("my-test-scope")
22
- assert_equal "", Pseudocephalopod.key_for_scope(nil)
23
- assert_equal "1", Pseudocephalopod.key_for_scope(1)
24
- assert_equal "awesome", Pseudocephalopod.key_for_scope(:awesome)
25
- end
26
-
27
- end
@@ -1,86 +0,0 @@
1
- require 'helper'
2
-
3
- class FakedModel
4
- attr_reader :id
5
- def self.slug_scope_key; "faked_models"; end
6
- def initialize(id); @id = id; end
7
- end
8
-
9
- class SlugHistoryTest < Test::Unit::TestCase
10
- with_tables :slugs, :users do
11
-
12
- context 'for arbitrary models' do
13
-
14
- setup do
15
- @record_a = FakedModel.new(12)
16
- @record_b = FakedModel.new(4)
17
- Pseudocephalopod.record_slug(@record_a, "awesome")
18
- Pseudocephalopod.record_slug(@record_b, "awesome-1")
19
- Pseudocephalopod.record_slug(@record_a, "ninjas")
20
- end
21
-
22
- should 'let you lookup a given record id easily' do
23
- assert Pseudocephalopod.last_known_slug_id(FakedModel, "felafel").blank?
24
- assert Pseudocephalopod.last_known_slug_id(FakedModel, "ninjas-2").blank?
25
- assert_equal 12, Pseudocephalopod.last_known_slug_id(FakedModel, "awesome")
26
- assert_equal 4, Pseudocephalopod.last_known_slug_id(FakedModel, "awesome-1")
27
- assert_equal 12, Pseudocephalopod.last_known_slug_id(FakedModel, "ninjas")
28
- end
29
-
30
- should 'let you return slug history for a given record'
31
-
32
- end
33
-
34
- context 'on a specific record' do
35
-
36
- should 'by default record slug history' do
37
- setup_slugs!
38
- user = User.create :name => "Bob"
39
- assert_equal [], user.previous_slugs
40
- user.update_attributes! :name => "Sal"
41
- user.update_attributes! :name => "Red"
42
- user.update_attributes! :name => "Jim"
43
- assert_same_as_slug user, "red"
44
- assert_same_as_slug user, "sal"
45
- assert_same_as_slug user, "bob"
46
- assert_same_as_slug user, "jim"
47
- end
48
-
49
- should 'let you reset history for a slug' do
50
- setup_slugs!
51
- user = User.create :name => "Bob"
52
- user.update_attributes! :name => "Sal"
53
- user.update_attributes! :name => "Red"
54
- user.update_attributes! :name => "Jim"
55
- assert_equal ["red", "sal", "bob"], user.previous_slugs
56
- user.remove_slug_history!
57
- assert_equal [], user.previous_slugs
58
- assert_none_for_slug "red"
59
- assert_none_for_slug "sal"
60
- assert_none_for_slug "bob"
61
- end
62
-
63
- should 'let you disable recording of slug history' do
64
- setup_slugs! :history => false
65
- user = User.create(:name => "Bob")
66
- assert !user.respond_to?(:previous_slugs)
67
- user.update_attributes! :name => "Red"
68
- assert_same_as_slug user, "red"
69
- assert_different_to_slug user, "bob"
70
- assert_none_for_slug "bob"
71
- end
72
-
73
- should 'remove slug history for a record by default on destroy' do
74
- setup_slugs!
75
- user = User.create :name => "Bob"
76
- user.update_attributes! :name => "Sal"
77
- user.update_attributes! :name => "Red"
78
- user.update_attributes! :name => "Jim"
79
- assert_equal ["red", "sal", "bob"], user.previous_slugs
80
- user.destroy
81
- assert_equal [], user.previous_slugs
82
- end
83
-
84
- end
85
- end
86
- end