socialization 0.5.0.beta3 → 0.5.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,153 +1,25 @@
1
1
  require File.expand_path(File.dirname(__FILE__))+'/../../test_helper'
2
2
 
3
3
  class RedisMentionStoreTest < Test::Unit::TestCase
4
- context "RedisStores::MentionStoreTest" do
4
+ context "RedisStores::Mention" do
5
5
  setup do
6
6
  use_redis_store
7
7
  @klass = Socialization::RedisStores::Mention
8
- @klass.touch nil
9
- @klass.after_mention nil
10
- @klass.after_unmention nil
11
- @mentioner = ImAMentioner.create
12
- @mentionable = ImAMentionable.create
8
+ @base = Socialization::RedisStores::Base
13
9
  end
14
10
 
15
- context "Stores" do
16
- should "inherit Socialization::RedisStores::Mention" do
17
- assert_equal Socialization::RedisStores::Mention, Socialization.mention_model
11
+ context "method aliases" do
12
+ should "be set properly and made public" do
13
+ assert_method_public @klass, :mention!
14
+ assert_method_public @klass, :unmention!
15
+ assert_method_public @klass, :mentions?
16
+ assert_method_public @klass, :mentioners_relation
17
+ assert_method_public @klass, :mentioners
18
+ assert_method_public @klass, :mentionables_relation
19
+ assert_method_public @klass, :mentionables
20
+ assert_method_public @klass, :remove_mentioners
21
+ assert_method_public @klass, :remove_mentionables
18
22
  end
19
23
  end
20
-
21
- context "#mention!" do
22
- should "create a Mention record" do
23
- @klass.mention!(@mentioner, @mentionable)
24
- assert_equal ["#{@mentioner.id}"], Socialization.redis.smembers(mentioners_key)
25
- assert_equal ["#{@mentionable.id}"], Socialization.redis.smembers(mentionables_key)
26
- end
27
-
28
- should "touch mentioner when instructed" do
29
- @klass.touch :mentioner
30
- @mentioner.expects(:touch).once
31
- @mentionable.expects(:touch).never
32
- @klass.mention!(@mentioner, @mentionable)
33
- end
34
-
35
- should "touch mentionable when instructed" do
36
- @klass.touch :mentionable
37
- @mentioner.expects(:touch).never
38
- @mentionable.expects(:touch).once
39
- @klass.mention!(@mentioner, @mentionable)
40
- end
41
-
42
- should "touch all when instructed" do
43
- @klass.touch :all
44
- @mentioner.expects(:touch).once
45
- @mentionable.expects(:touch).once
46
- @klass.mention!(@mentioner, @mentionable)
47
- end
48
-
49
- should "call after mention hook" do
50
- @klass.after_mention :after_mention
51
- @klass.expects(:after_mention).once
52
- @klass.mention!(@mentioner, @mentionable)
53
- end
54
-
55
- should "call after unmention hook" do
56
- @klass.after_mention :after_unmention
57
- @klass.expects(:after_unmention).once
58
- @klass.mention!(@mentioner, @mentionable)
59
- end
60
- end
61
-
62
- context "#mentions?" do
63
- should "return true when mention exists" do
64
- Socialization.redis.sadd mentioners_key, @mentioner.id
65
- Socialization.redis.sadd mentionables_key, @mentionable.id
66
- assert_true @klass.mentions?(@mentioner, @mentionable)
67
- end
68
-
69
- should "return false when mention doesn't exist" do
70
- assert_false @klass.mentions?(@mentioner, @mentionable)
71
- end
72
- end
73
-
74
- context "#mentioners" do
75
- should "return an array of mentioners" do
76
- mentioner1 = ImAMentioner.create
77
- mentioner2 = ImAMentioner.create
78
- mentioner1.mention!(@mentionable)
79
- mentioner2.mention!(@mentionable)
80
- assert_array_similarity [mentioner1, mentioner2], @klass.mentioners(@mentionable, mentioner1.class)
81
- end
82
-
83
- should "return an array of mentioner ids when plucking" do
84
- mentioner1 = ImAMentioner.create
85
- mentioner2 = ImAMentioner.create
86
- mentioner1.mention!(@mentionable)
87
- mentioner2.mention!(@mentionable)
88
- assert_array_similarity [mentioner1.id, mentioner2.id], @klass.mentioners(@mentionable, mentioner1.class, :pluck => :id)
89
- end
90
- end
91
-
92
- context "#mentionables" do
93
- should "return an array of mentionables" do
94
- mentionable1 = ImAMentionable.create
95
- mentionable2 = ImAMentionable.create
96
- @mentioner.mention!(mentionable1)
97
- @mentioner.mention!(mentionable2)
98
-
99
- assert_array_similarity [mentionable1, mentionable2], @klass.mentionables(@mentioner, mentionable1.class)
100
- end
101
-
102
- should "return an array of mentionables ids when plucking" do
103
- mentionable1 = ImAMentionable.create
104
- mentionable2 = ImAMentionable.create
105
- @mentioner.mention!(mentionable1)
106
- @mentioner.mention!(mentionable2)
107
- assert_array_similarity [mentionable1.id, mentionable2.id], @klass.mentionables(@mentioner, mentionable1.class, :pluck => :id)
108
- end
109
- end
110
-
111
- context "#generate_mentioners_key" do
112
- should "return valid key when passed objects" do
113
- assert_equal "Mentioners:ImAMentionable:#{@mentionable.id}:ImAMentioner", mentioners_key(@mentioner, @mentionable)
114
- end
115
-
116
- should "return valid key when mentioner is a class" do
117
- assert_equal "Mentioners:ImAMentionable:#{@mentionable.id}:ImAMentioner", mentioners_key(@mentioner.class, @mentionable)
118
- end
119
- end
120
-
121
- context "#generate_mentionables_key" do
122
- should "return valid key when passed objects" do
123
- assert_equal "Mentionables:ImAMentioner:#{@mentioner.id}:ImAMentionable", mentionables_key(@mentioner, @mentionable)
124
- end
125
-
126
- should "return valid key when mentionable is a class" do
127
- assert_equal "Mentionables:ImAMentioner:#{@mentioner.id}:ImAMentionable", mentionables_key(@mentioner, @mentionable.class)
128
- end
129
- end
130
-
131
- end
132
-
133
- # Helpers
134
- def assert_match_mentioner(mention_record, mentioner)
135
- assert mention_record.mentioner_type == mentioner.class.to_s && mention_record.mentioner_id == mentioner.id
136
- end
137
-
138
- def assert_match_mentionable(mention_record, mentionable)
139
- assert mention_record.mentionable_type == mentionable.class.to_s && mention_record.mentionable_id == mentionable.id
140
- end
141
-
142
- def mentioners_key(mentioner = nil, mentionable = nil)
143
- mentioner ||= @mentioner
144
- mentionable ||= @mentionable
145
- @klass.send(:generate_mentioners_key, mentioner, mentionable)
146
- end
147
-
148
- def mentionables_key(mentioner = nil, mentionable = nil)
149
- mentioner ||= @mentioner
150
- mentionable ||= @mentionable
151
- @klass.send(:generate_mentionables_key, mentioner, mentionable)
152
24
  end
153
- end
25
+ end
data/test/test_helper.rb CHANGED
@@ -8,6 +8,7 @@ require 'logger'
8
8
  require 'mock_redis' if $MOCK_REDIS
9
9
  require 'redis' unless $MOCK_REDIS
10
10
  require 'mocha' # mocha always needs to be loaded last! http://stackoverflow.com/questions/3118866/mocha-mock-carries-to-another-test/4375296#4375296
11
+ # require 'pry'
11
12
 
12
13
  $:.push File.expand_path("../lib", __FILE__)
13
14
  require "socialization"
@@ -29,6 +30,23 @@ module Test::Unit::Assertions
29
30
  full_message = build_message(message, "<?> expected but was\n<?>.\n", expected, actual)
30
31
  assert_block(full_message) { (expected.size == actual.size) && (expected - actual == []) }
31
32
  end
33
+
34
+ def assert_empty(obj, msg = nil)
35
+ msg = "Expected #{obj.inspect} to be empty" unless msg
36
+ assert_respond_to obj, :empty?
37
+ assert obj.empty?, msg
38
+ end
39
+
40
+ def assert_method_public(obj, method, msg = nil)
41
+ msg = "Expected method #{obj}.#{method} to be public."
42
+ method = if RUBY_VERSION.match(/^1\.8/)
43
+ method.to_s
44
+ else
45
+ method.to_s.to_sym
46
+ end
47
+
48
+ assert obj.public_methods.include?(method), msg
49
+ end
32
50
  end
33
51
 
34
52
  class Test::Unit::TestCase
@@ -44,5 +44,17 @@ class FollowableTest < Test::Unit::TestCase
44
44
  end
45
45
  end
46
46
 
47
+ context "deleting a followable" do
48
+ setup do
49
+ @follower = ImAFollower.create
50
+ @follower.follow!(@followable)
51
+ end
52
+
53
+ should "remove follow relationships" do
54
+ Socialization.follow_model.expects(:remove_followers).with(@followable)
55
+ @followable.destroy
56
+ end
57
+ end
58
+
47
59
  end
48
60
  end
@@ -43,5 +43,18 @@ class LikeableTest < Test::Unit::TestCase
43
43
  @likeable.likers_relation(@liker.class, { :foo => :bar })
44
44
  end
45
45
  end
46
+
47
+ context "deleting a likeable" do
48
+ setup do
49
+ @liker = ImALiker.create
50
+ @liker.like!(@likeable)
51
+ end
52
+
53
+ should "remove like relationships" do
54
+ Socialization.like_model.expects(:remove_likers).with(@likeable)
55
+ @likeable.destroy
56
+ end
57
+ end
58
+
46
59
  end
47
60
  end
@@ -43,5 +43,18 @@ class MentionableTest < Test::Unit::TestCase
43
43
  @mentionable.mentioners_relation(@mentioner.class, { :foo => :bar })
44
44
  end
45
45
  end
46
+
47
+ context "deleting a mentionable" do
48
+ setup do
49
+ @mentioner = ImAMentioner.create
50
+ @mentioner.mention!(@mentionable)
51
+ end
52
+
53
+ should "remove mention relationships" do
54
+ Socialization.mention_model.expects(:remove_mentioners).with(@mentionable)
55
+ @mentionable.destroy
56
+ end
57
+ end
58
+
46
59
  end
47
60
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socialization
3
3
  version: !ruby/object:Gem::Version
4
- hash: 699693383
4
+ hash: -1691710682
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
9
  - 0
10
10
  - beta
11
- - 3
12
- version: 0.5.0.beta3
11
+ - 4
12
+ version: 0.5.0.beta4
13
13
  platform: ruby
14
14
  authors:
15
15
  - Carl Mercier
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-07-05 00:00:00 -04:00
20
+ date: 2012-08-07 00:00:00 -04:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -260,6 +260,7 @@ files:
260
260
  - test/stores/active_record/follow_store_test.rb
261
261
  - test/stores/active_record/like_store_test.rb
262
262
  - test/stores/active_record/mention_store_test.rb
263
+ - test/stores/redis/base_test.rb
263
264
  - test/stores/redis/config_test.rb
264
265
  - test/stores/redis/follow_store_test.rb
265
266
  - test/stores/redis/like_store_test.rb
@@ -313,6 +314,7 @@ test_files:
313
314
  - test/stores/active_record/follow_store_test.rb
314
315
  - test/stores/active_record/like_store_test.rb
315
316
  - test/stores/active_record/mention_store_test.rb
317
+ - test/stores/redis/base_test.rb
316
318
  - test/stores/redis/config_test.rb
317
319
  - test/stores/redis/follow_store_test.rb
318
320
  - test/stores/redis/like_store_test.rb