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 CHANGED
@@ -79,7 +79,7 @@ How do you notify commenters when new comment is posted for an article?
79
79
 
80
80
  Add this line to your application's Gemfile:
81
81
 
82
- gem 'horde'
82
+ gem 'horde-rails', :require => 'horde'
83
83
 
84
84
  And then execute:
85
85
 
@@ -23,11 +23,18 @@ module Horde
23
23
 
24
24
  # user favorite something.
25
25
  def favorite(target, options = {})
26
- params = {:actor_id => self.id,
27
- :target_id => target.id,
28
- :target_type => target.class.name
29
- }.merge(options)
30
- fav = ::Horde::Favorite.create(params)
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
@@ -23,11 +23,19 @@ module Horde
23
23
 
24
24
  # user follow something.
25
25
  def follow(target, options = {})
26
- params = {:actor_id => self.id,
27
- :target_id => target.id,
28
- :target_type => target.class.name
29
- }.merge(options)
30
- follow = ::Horde::Follow.create(params)
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
@@ -25,11 +25,18 @@ module Horde
25
25
 
26
26
  # user rate something.
27
27
  def rate(target, options = {})
28
- params = {:actor_id => self.id,
29
- :target_id => target.id,
30
- :target_type => target.class.name
31
- }.merge(options)
32
- rate = ::Horde::Rate.create(params)
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
@@ -1,3 +1,3 @@
1
1
  module Horde
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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
@@ -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
@@ -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
@@ -6,4 +6,4 @@ test:
6
6
  pool: 1
7
7
  username: root
8
8
  password:
9
- socket: /opt/local/var/run/mysql5/mysqld.sock
9
+ #socket: /opt/local/var/run/mysql5/mysqld.sock
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.1
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-07-15 00:00:00.000000000 Z
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: 4029953517073986462
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: 4029953517073986462
203
+ hash: -3914311186936827395
204
204
  requirements: []
205
205
  rubyforge_project:
206
206
  rubygems_version: 1.8.24