horde-rails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/horde/actions/favorite.rb +12 -5
- data/lib/horde/actions/follow.rb +13 -5
- data/lib/horde/actions/rate.rb +12 -5
- data/lib/horde/version.rb +1 -1
- data/spec/favorite_spec.rb +7 -0
- data/spec/follow_spec.rb +7 -0
- data/spec/rate_spec.rb +9 -0
- data/spec/support/database.yml +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -23,11 +23,18 @@ module Horde
|
|
23
23
|
|
24
24
|
# user favorite something.
|
25
25
|
def favorite(target, options = {})
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
fav = ::Horde::Favorite.
|
26
|
+
pks = {:actor_id => self.id,
|
27
|
+
:target_id => target.id,
|
28
|
+
:target_type => target.class.name
|
29
|
+
}.merge(options)
|
30
|
+
fav = ::Horde::Favorite.where(pks).first
|
31
|
+
if fav
|
32
|
+
# do nothing
|
33
|
+
else
|
34
|
+
params = pks.merge(options)
|
35
|
+
fav = ::Horde::Favorite.create(params)
|
36
|
+
end
|
37
|
+
|
31
38
|
target.run_hook(:after_favorite, fav)
|
32
39
|
|
33
40
|
fav
|
data/lib/horde/actions/follow.rb
CHANGED
@@ -23,11 +23,19 @@ module Horde
|
|
23
23
|
|
24
24
|
# user follow something.
|
25
25
|
def follow(target, options = {})
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
pks = {:actor_id => self.id,
|
27
|
+
:target_id => target.id,
|
28
|
+
:target_type => target.class.name
|
29
|
+
}.merge(options)
|
30
|
+
|
31
|
+
follow = ::Horde::Follow.where(pks).first
|
32
|
+
if follow
|
33
|
+
# do nothing
|
34
|
+
else
|
35
|
+
params = pks.merge(options)
|
36
|
+
follow = ::Horde::Follow.create(params)
|
37
|
+
end
|
38
|
+
|
31
39
|
target.run_hook(:after_follow, follow)
|
32
40
|
|
33
41
|
follow
|
data/lib/horde/actions/rate.rb
CHANGED
@@ -25,11 +25,18 @@ module Horde
|
|
25
25
|
|
26
26
|
# user rate something.
|
27
27
|
def rate(target, options = {})
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
rate = ::Horde::Rate.
|
28
|
+
pks = {:actor_id => self.id,
|
29
|
+
:target_id => target.id,
|
30
|
+
:target_type => target.class.name
|
31
|
+
}
|
32
|
+
rate = ::Horde::Rate.where(pks).first
|
33
|
+
if rate
|
34
|
+
rate.update_attributes(options)
|
35
|
+
else
|
36
|
+
params = pks.merge(options)
|
37
|
+
rate = ::Horde::Rate.create(params)
|
38
|
+
end
|
39
|
+
|
33
40
|
target.run_hook(:after_rate, rate)
|
34
41
|
|
35
42
|
rate
|
data/lib/horde/version.rb
CHANGED
data/spec/favorite_spec.rb
CHANGED
@@ -38,4 +38,11 @@ describe "favoriting" do
|
|
38
38
|
article2.should_receive(:run_hook)
|
39
39
|
@user.favorite(article2)
|
40
40
|
end
|
41
|
+
|
42
|
+
it "should not favorite same thing twice" do
|
43
|
+
@article.favorites.size.should == 1
|
44
|
+
|
45
|
+
@user.favorite(@article)
|
46
|
+
@article.favorites.size.should == 1
|
47
|
+
end
|
41
48
|
end
|
data/spec/follow_spec.rb
CHANGED
@@ -52,4 +52,11 @@ describe "following" do
|
|
52
52
|
@user2.follows.should == [follow]
|
53
53
|
@user2.followers.should == [@user]
|
54
54
|
end
|
55
|
+
|
56
|
+
it "should not follow same thing twice" do
|
57
|
+
@article.follows.size.should == 1
|
58
|
+
|
59
|
+
@user.follow(@article)
|
60
|
+
@article.follows.size.should == 1
|
61
|
+
end
|
55
62
|
end
|
data/spec/rate_spec.rb
CHANGED
@@ -38,4 +38,13 @@ describe "rating" do
|
|
38
38
|
article2.should_receive(:run_hook)
|
39
39
|
@user.rate(article2)
|
40
40
|
end
|
41
|
+
|
42
|
+
it "should not rate same thing twice" do
|
43
|
+
@article.rates.size.should == 1
|
44
|
+
@article.rates.first.score.should == 5
|
45
|
+
|
46
|
+
@user.rate(@article, :score => 4)
|
47
|
+
@article.rates.size.should == 1
|
48
|
+
@article.rates.first.score.should == 4
|
49
|
+
end
|
41
50
|
end
|
data/spec/support/database.yml
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: horde-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mysql2
|
@@ -191,7 +191,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
191
191
|
version: '0'
|
192
192
|
segments:
|
193
193
|
- 0
|
194
|
-
hash:
|
194
|
+
hash: -3914311186936827395
|
195
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
196
|
none: false
|
197
197
|
requirements:
|
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
200
|
version: '0'
|
201
201
|
segments:
|
202
202
|
- 0
|
203
|
-
hash:
|
203
|
+
hash: -3914311186936827395
|
204
204
|
requirements: []
|
205
205
|
rubyforge_project:
|
206
206
|
rubygems_version: 1.8.24
|