partisan 0.2.1 → 0.2.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.
- data/.travis.yml +7 -0
- data/README.md +8 -10
- data/lib/partisan/follow.rb +2 -2
- data/lib/partisan/followable.rb +1 -1
- data/lib/partisan/follower.rb +1 -1
- data/lib/partisan/version.rb +1 -1
- data/spec/{followable_spec.rb → support/followable_spec.rb} +2 -2
- data/spec/{follower_spec.rb → support/follower_spec.rb} +18 -4
- data/spec/support/macros/model_macros.rb +9 -0
- metadata +9 -8
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Partisan
|
2
2
|
|
3
|
+
[](https://rubygems.org/gems/partisan)
|
4
|
+
[](https://travis-ci.org/mirego/partisan)
|
5
|
+
|
3
6
|
Partisan is a Ruby library that allows ActiveRecord records to follow other records.
|
4
7
|
|
5
8
|
It’s heavily inspired by `acts_as_follower`. However, it’s not 100% compatible with `acts_as_follower` as I removed some “features”:
|
@@ -21,7 +24,7 @@ Add this line to your application’s Gemfile:
|
|
21
24
|
gem 'partisan'
|
22
25
|
```
|
23
26
|
|
24
|
-
And then execute
|
27
|
+
And then execute
|
25
28
|
|
26
29
|
```bash
|
27
30
|
$ bundle
|
@@ -81,7 +84,7 @@ band.followers_count
|
|
81
84
|
# Quick lookup into the column and returns `1`
|
82
85
|
```
|
83
86
|
|
84
|
-
The same concept applies to `followable` with a `
|
87
|
+
The same concept applies to `followable` with a `followings_count` column.
|
85
88
|
|
86
89
|
### Callbacks
|
87
90
|
|
@@ -135,11 +138,6 @@ The available callbacks are:
|
|
135
138
|
|
136
139
|
## About Mirego
|
137
140
|
|
138
|
-
Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun.
|
139
|
-
|
140
|
-
[
|
141
|
-
[iPad](http://mirego.com/en/ipad-app-development/ "iPad application development"),
|
142
|
-
[Android](http://mirego.com/en/android-app-development/ "Android application development"),
|
143
|
-
[Blackberry](http://mirego.com/en/blackberry-app-development/ "Blackberry application development"),
|
144
|
-
[Windows Phone](http://mirego.com/en/windows-phone-app-development/ "Windows Phone application development") and
|
145
|
-
[Windows 8](http://mirego.com/en/windows-8-app-development/ "Windows 8 application development").
|
141
|
+
Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We proudly build mobile applications for [iPhone](http://mirego.com/en/iphone-app-development/ "iPhone application development"), [iPad](http://mirego.com/en/ipad-app-development/ "iPad application development"), [Android](http://mirego.com/en/android-app-development/ "Android application development"), [Blackberry](http://mirego.com/en/blackberry-app-development/ "Blackberry application development"), [Windows Phone](http://mirego.com/en/windows-phone-app-development/ "Windows Phone application development") and [Windows 8](http://mirego.com/en/windows-8-app-development/ "Windows 8 application development") in beautiful Quebec City.
|
142
|
+
|
143
|
+
We also love [open-source software](http://open.mirego.com/) and we try to extract as much code as possible from our projects to give back to the community.
|
data/lib/partisan/follow.rb
CHANGED
data/lib/partisan/followable.rb
CHANGED
@@ -54,7 +54,7 @@ module Partisan
|
|
54
54
|
|
55
55
|
# Update cache counter
|
56
56
|
# Called in after_create and after_destroy
|
57
|
-
def
|
57
|
+
def update_followable_counter
|
58
58
|
self.update_attribute('followers_count', self.followings.count) if self.respond_to?(:followers_count)
|
59
59
|
end
|
60
60
|
|
data/lib/partisan/follower.rb
CHANGED
@@ -96,7 +96,7 @@ module Partisan
|
|
96
96
|
|
97
97
|
# Update cache counter
|
98
98
|
# Called in after_create and after_destroy
|
99
|
-
def
|
99
|
+
def update_follower_counter
|
100
100
|
self.update_attribute('followings_count', self.follows.count) if self.respond_to?(:followings_count)
|
101
101
|
end
|
102
102
|
|
data/lib/partisan/version.rb
CHANGED
@@ -37,7 +37,7 @@ describe Partisan::Followable do
|
|
37
37
|
|
38
38
|
describe :followers_by_type do
|
39
39
|
it { expect(band.followers_by_type('User').count).to eq 1 }
|
40
|
-
it { expect(band.followers_by_type('User')).to be_an_instance_of(ActiveRecord::Relation) }
|
40
|
+
it { expect(band.followers_by_type('User')).to be_an_instance_of(ActiveRecord::Relation::ActiveRecord_Relation_User) }
|
41
41
|
it { expect(band.followers_by_type('User').first).to be_an_instance_of(User) }
|
42
42
|
it { expect(band.followers_by_type('Fan').count).to eq 0 }
|
43
43
|
end
|
@@ -50,7 +50,7 @@ describe Partisan::Followable do
|
|
50
50
|
|
51
51
|
describe :followers_by_type_in_method_missing do
|
52
52
|
it { expect(band.user_followers.count).to eq 1 }
|
53
|
-
it { expect(band.user_followers).to be_an_instance_of(ActiveRecord::Relation) }
|
53
|
+
it { expect(band.user_followers).to be_an_instance_of(ActiveRecord::Relation::ActiveRecord_Relation_User) }
|
54
54
|
it { expect(band.user_followers.first).to be_an_instance_of(User) }
|
55
55
|
it { expect(band.fan_followers.count).to eq 0 }
|
56
56
|
end
|
@@ -5,20 +5,34 @@ describe Partisan::Follower do
|
|
5
5
|
run_migration do
|
6
6
|
create_table(:users, force: true) do |t|
|
7
7
|
t.integer :followings_count, default: 0
|
8
|
+
t.integer :followers_count, default: 0
|
8
9
|
end
|
9
10
|
create_table(:concerts, force: true)
|
10
11
|
create_table(:bands, force: true)
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
+
followable_and_follower 'User'
|
14
15
|
followable 'Band'
|
15
16
|
followable 'Concert'
|
16
17
|
end
|
17
18
|
|
18
19
|
let(:band) { Band.create }
|
19
20
|
let(:user) { User.create }
|
21
|
+
let(:user2) { User.create }
|
20
22
|
let(:concert) { Concert.create }
|
21
23
|
|
24
|
+
describe :UserToUser do
|
25
|
+
before do
|
26
|
+
user.follow user2
|
27
|
+
|
28
|
+
user.reload
|
29
|
+
user2.reload
|
30
|
+
end
|
31
|
+
|
32
|
+
it { expect(user.followings_count).to eq 1 }
|
33
|
+
it { expect(user2.followers_count).to eq 1 }
|
34
|
+
end
|
35
|
+
|
22
36
|
describe :InstanceMethods do
|
23
37
|
before do
|
24
38
|
user.follow band
|
@@ -44,7 +58,7 @@ describe Partisan::Follower do
|
|
44
58
|
|
45
59
|
describe :following_by_type do
|
46
60
|
it { expect(user.following_by_type('Band').count).to eq 1 }
|
47
|
-
it { expect(user.following_by_type('Band')).to be_an_instance_of(ActiveRecord::Relation) }
|
61
|
+
it { expect(user.following_by_type('Band')).to be_an_instance_of(ActiveRecord::Relation::ActiveRecord_Relation_Band) }
|
48
62
|
it { expect(user.following_by_type('Band').first).to be_an_instance_of(Band) }
|
49
63
|
it { expect(user.following_by_type('Concert').count).to eq 0 }
|
50
64
|
end
|
@@ -57,11 +71,11 @@ describe Partisan::Follower do
|
|
57
71
|
|
58
72
|
describe :following_by_type_in_method_missing do
|
59
73
|
it { expect(user.following_bands.count).to eq 1 }
|
60
|
-
it { expect(user.following_bands).to be_an_instance_of(ActiveRecord::Relation) }
|
74
|
+
it { expect(user.following_bands).to be_an_instance_of(ActiveRecord::Relation::Relation::ActiveRecord_Relation_Band) }
|
61
75
|
it { expect(user.following_bands.first).to be_an_instance_of(Band) }
|
62
76
|
|
63
77
|
it { expect(user.following_concerts.count).to eq 0 }
|
64
|
-
it { expect(user.following_concerts).to be_an_instance_of(ActiveRecord::Relation) }
|
78
|
+
it { expect(user.following_concerts).to be_an_instance_of(ActiveRecord::Relation::Relation::ActiveRecord_Relation_Concert) }
|
65
79
|
end
|
66
80
|
|
67
81
|
describe :following_fields_by_type_in_method_missing do
|
@@ -15,6 +15,15 @@ module ModelMacros
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
# Create a new emotive and emotionnal model
|
19
|
+
def followable_and_follower(klass_name, &block)
|
20
|
+
spawn_model klass_name, ActiveRecord::Base do
|
21
|
+
acts_as_followable
|
22
|
+
acts_as_follower
|
23
|
+
class_eval(&block) if block
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
18
27
|
protected
|
19
28
|
|
20
29
|
# Create a new model class
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: partisan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-07-
|
13
|
+
date: 2013-07-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -104,6 +104,7 @@ extra_rdoc_files: []
|
|
104
104
|
files:
|
105
105
|
- .gitignore
|
106
106
|
- .rspec
|
107
|
+
- .travis.yml
|
107
108
|
- Gemfile
|
108
109
|
- LICENSE.md
|
109
110
|
- README.md
|
@@ -119,9 +120,9 @@ files:
|
|
119
120
|
- lib/partisan/railtie.rb
|
120
121
|
- lib/partisan/version.rb
|
121
122
|
- partisan.gemspec
|
122
|
-
- spec/followable_spec.rb
|
123
|
-
- spec/follower_spec.rb
|
124
123
|
- spec/spec_helper.rb
|
124
|
+
- spec/support/followable_spec.rb
|
125
|
+
- spec/support/follower_spec.rb
|
125
126
|
- spec/support/macros/database_macros.rb
|
126
127
|
- spec/support/macros/model_macros.rb
|
127
128
|
homepage: https://github.com/mirego/partisan
|
@@ -139,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
140
|
version: '0'
|
140
141
|
segments:
|
141
142
|
- 0
|
142
|
-
hash:
|
143
|
+
hash: 390646380941659305
|
143
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
145
|
none: false
|
145
146
|
requirements:
|
@@ -148,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
149
|
version: '0'
|
149
150
|
segments:
|
150
151
|
- 0
|
151
|
-
hash:
|
152
|
+
hash: 390646380941659305
|
152
153
|
requirements: []
|
153
154
|
rubyforge_project:
|
154
155
|
rubygems_version: 1.8.23
|
@@ -157,8 +158,8 @@ specification_version: 3
|
|
157
158
|
summary: Partisan is a Ruby library that allows ActiveRecord records to be follower
|
158
159
|
and followable
|
159
160
|
test_files:
|
160
|
-
- spec/followable_spec.rb
|
161
|
-
- spec/follower_spec.rb
|
162
161
|
- spec/spec_helper.rb
|
162
|
+
- spec/support/followable_spec.rb
|
163
|
+
- spec/support/follower_spec.rb
|
163
164
|
- spec/support/macros/database_macros.rb
|
164
165
|
- spec/support/macros/model_macros.rb
|