emotions 0.3 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +56 -0
- data/.travis.yml +4 -1
- data/LICENSE.md +1 -1
- data/README.md +1 -1
- data/emotions.gemspec +4 -2
- data/lib/emotions.rb +6 -6
- data/lib/emotions/emotion.rb +3 -3
- data/lib/emotions/emotional.rb +17 -5
- data/lib/emotions/emotive.rb +3 -3
- data/lib/emotions/railtie.rb +1 -1
- data/lib/emotions/version.rb +1 -1
- data/lib/generators/emotions/install_generator.rb +2 -2
- data/lib/generators/emotions/templates/migration.rb +1 -1
- data/spec/emotions/emotion_spec.rb +16 -16
- data/spec/emotions/emotional_spec.rb +51 -39
- data/spec/emotions/emotive_spec.rb +2 -4
- data/spec/spec_helper.rb +6 -1
- data/spec/support/macros/database_macros.rb +2 -2
- metadata +49 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b63d3b7d828f862c2826496b55366c15185ad19
|
4
|
+
data.tar.gz: 14d555b43d50e343a58b5ac5e954bda1cb7c3dc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6462ae7e461615499b461e71f2cc93c29701e5961719090339116a1a53e219b305a1e9a81576df289ba40ba90849004544b943f323418fc2ef8a84f6b374e71a
|
7
|
+
data.tar.gz: 4618ff14f5a8dc019a9c9c0269b3cecc68d403d0f5a44e969a7601632d68dba7cd6f0352857ad649f7b78afaed7334b18262ce22e59213f04a07b31c94e4b6bf
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
AllCops:
|
2
|
+
Include:
|
3
|
+
- emotions.gemspec
|
4
|
+
|
5
|
+
Documentation:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Encoding:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
LineLength:
|
12
|
+
Max: 200
|
13
|
+
|
14
|
+
ClassLength:
|
15
|
+
Max: 200
|
16
|
+
|
17
|
+
AccessModifierIndentation:
|
18
|
+
EnforcedStyle: outdent
|
19
|
+
|
20
|
+
IfUnlessModifier:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
CaseIndentation:
|
24
|
+
IndentWhenRelativeTo: case
|
25
|
+
IndentOneStep: true
|
26
|
+
|
27
|
+
MethodLength:
|
28
|
+
CountComments: false
|
29
|
+
Max: 20
|
30
|
+
|
31
|
+
SignalException:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
ColonMethodCall:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
AsciiComments:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Lambda:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
RegexpLiteral:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
RaiseArgs:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
AssignmentInCondition:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
ClassAndModuleChildren:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
GuardClause:
|
56
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -110,7 +110,7 @@ user.happy_emotions_count
|
|
110
110
|
|
111
111
|
## License
|
112
112
|
|
113
|
-
`Emotions` is © 2013 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/emotions/blob/master/LICENSE.md) file.
|
113
|
+
`Emotions` is © 2013-2014 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/emotions/blob/master/LICENSE.md) file.
|
114
114
|
|
115
115
|
## About Mirego
|
116
116
|
|
data/emotions.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = 'https://github.com/mirego/emotions'
|
14
14
|
spec.license = 'BSD 3-Clause'
|
15
15
|
|
16
|
-
spec.files = `git ls-files`.split(
|
16
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_development_dependency 'rake'
|
24
24
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
-
spec.add_development_dependency 'rspec', '~>
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.1'
|
26
26
|
spec.add_development_dependency 'sqlite3', '~> 1.3'
|
27
|
+
spec.add_development_dependency 'phare', '~> 0.7'
|
28
|
+
spec.add_development_dependency 'rubocop', '0.31'
|
27
29
|
end
|
data/lib/emotions.rb
CHANGED
@@ -18,25 +18,25 @@ module Emotions
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.inject_into_active_record
|
21
|
-
@inject_into_active_record ||=
|
21
|
+
@inject_into_active_record ||= proc do
|
22
22
|
def self.acts_as_emotive
|
23
|
-
|
23
|
+
send :include, Emotions::Emotive
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.acts_as_emotional
|
27
|
-
|
27
|
+
send :include, Emotions::Emotional
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.acts_as_emotion
|
31
|
-
|
31
|
+
send :include, Emotions::Emotion
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.emotional?
|
35
|
-
@emotional ||=
|
35
|
+
@emotional ||= ancestors.include?(Emotions::Emotional)
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.emotive?
|
39
|
-
@emotive ||=
|
39
|
+
@emotive ||= ancestors.include?(Emotions::Emotive)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
data/lib/emotions/emotion.rb
CHANGED
@@ -25,13 +25,13 @@ module Emotions
|
|
25
25
|
|
26
26
|
# Update the `<emotion>_emotions_counter` for the emotive record
|
27
27
|
def update_emotion_counter
|
28
|
-
|
29
|
-
|
28
|
+
emotive.update_emotion_counter(emotion)
|
29
|
+
emotional.update_emotion_counter(emotion)
|
30
30
|
end
|
31
31
|
|
32
32
|
# Make sure we're using an allowed emotion name
|
33
33
|
def ensure_valid_emotion_name
|
34
|
-
unless Emotions.emotions.include?(
|
34
|
+
unless Emotions.emotions.include?(emotion.try(:to_sym))
|
35
35
|
errors.add :emotion, I18n.t(:invalid, scope: [:errors, :messages])
|
36
36
|
end
|
37
37
|
end
|
data/lib/emotions/emotional.rb
CHANGED
@@ -12,7 +12,7 @@ module Emotions
|
|
12
12
|
|
13
13
|
# @private
|
14
14
|
def _emotions_about(emotive)
|
15
|
-
|
15
|
+
emotions.where(emotive_id: emotive.id, emotive_type: emotive.class.name)
|
16
16
|
end
|
17
17
|
|
18
18
|
# Return all emotions expressed by the emotional record
|
@@ -58,11 +58,21 @@ module Emotions
|
|
58
58
|
def update_emotion_counter(emotion)
|
59
59
|
attribute = "#{emotion}_emotions_count"
|
60
60
|
|
61
|
-
if
|
62
|
-
|
61
|
+
if respond_to?(attribute)
|
62
|
+
update_attribute(attribute, send("#{emotion}_about").count)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
# Find if an emotion is expressed towards another record
|
67
|
+
#
|
68
|
+
# @example
|
69
|
+
# user = User.first
|
70
|
+
# picture = Picture.first
|
71
|
+
# user.express? :happy, picture
|
72
|
+
def express?(emotion, emotive)
|
73
|
+
_emotions_about(emotive).where(emotion: emotion).any?
|
74
|
+
end
|
75
|
+
|
66
76
|
module ClassMethods
|
67
77
|
# Return an `ActiveRecord::Relation` containing the emotional records
|
68
78
|
# that expressed a specific emotion towards an emotive record
|
@@ -75,7 +85,7 @@ module Emotions
|
|
75
85
|
# # => #<ActiveRecord::Relation [#<User id=1>]>
|
76
86
|
def emotional_about(emotion, emotive)
|
77
87
|
if emotive.class.emotive?
|
78
|
-
emotional_ids = emotive.emotions.where(emotion: emotion).where(emotional_type:
|
88
|
+
emotional_ids = emotive.emotions.where(emotion: emotion).where(emotional_type: name).pluck(:emotional_id)
|
79
89
|
where(id: emotional_ids)
|
80
90
|
else
|
81
91
|
# ActiveRecord 4 supports `.none`, not ActiveRecord 3
|
@@ -83,6 +93,7 @@ module Emotions
|
|
83
93
|
end
|
84
94
|
end
|
85
95
|
|
96
|
+
# rubocop:disable MethodLength
|
86
97
|
def define_emotion_methods(emotion)
|
87
98
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
88
99
|
def #{emotion}_about?(emotive)
|
@@ -98,7 +109,7 @@ module Emotions
|
|
98
109
|
end
|
99
110
|
|
100
111
|
def #{emotion}_about(emotive = nil)
|
101
|
-
relation = emotive.nil? ?
|
112
|
+
relation = emotive.nil? ? emotions : _emotions_about(emotive)
|
102
113
|
relation.where(emotion: #{emotion.to_s.inspect})
|
103
114
|
end
|
104
115
|
|
@@ -125,6 +136,7 @@ module Emotions
|
|
125
136
|
alias #{emotion}_over #{emotion}_about
|
126
137
|
RUBY
|
127
138
|
end
|
139
|
+
# rubocop:enable MethodLength
|
128
140
|
end
|
129
141
|
end
|
130
142
|
end
|
data/lib/emotions/emotive.rb
CHANGED
@@ -14,8 +14,8 @@ module Emotions
|
|
14
14
|
def update_emotion_counter(emotion)
|
15
15
|
attribute = "#{emotion}_emotions_count"
|
16
16
|
|
17
|
-
if
|
18
|
-
|
17
|
+
if respond_to?(attribute)
|
18
|
+
update_attribute(attribute, send("#{emotion}_about").count)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -24,7 +24,7 @@ module Emotions
|
|
24
24
|
def define_emotion_methods(emotion)
|
25
25
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
26
26
|
def #{emotion}_about
|
27
|
-
|
27
|
+
emotions.where(emotion: #{emotion.to_s.inspect})
|
28
28
|
end
|
29
29
|
alias #{emotion}_with #{emotion}_about
|
30
30
|
alias #{emotion}_over #{emotion}_about
|
data/lib/emotions/railtie.rb
CHANGED
data/lib/emotions/version.rb
CHANGED
@@ -13,7 +13,7 @@ module Emotions
|
|
13
13
|
if ActiveRecord::Base.timestamped_migrations
|
14
14
|
Time.now.utc.strftime('%Y%m%d%H%M%S')
|
15
15
|
else
|
16
|
-
|
16
|
+
'%.3d'.format(current_migration_number(dirname) + 1)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -22,7 +22,7 @@ module Emotions
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def create_model_file
|
25
|
-
template
|
25
|
+
template 'model.rb', 'app/models/emotion.rb'
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -10,7 +10,7 @@ class AddEmotions < ActiveRecord::Migration
|
|
10
10
|
# The type of emotion
|
11
11
|
t.string :emotion
|
12
12
|
|
13
|
-
t.timestamps
|
13
|
+
t.timestamps null: false
|
14
14
|
end
|
15
15
|
|
16
16
|
add_index :emotions, [:emotional_type, :emotional_id, :emotive_type, :emotive_id, :emotion], unique: true, name: 'index_emotions_by_emotional_emotive_and_emotion'
|
@@ -21,40 +21,40 @@ describe Emotions::Emotion do
|
|
21
21
|
subject { Emotion.new(emotion: 'happy', emotive: Picture.create) }
|
22
22
|
before { subject.valid? }
|
23
23
|
|
24
|
-
it {
|
25
|
-
it { expect(subject.errors.full_messages).to eql [
|
24
|
+
it { expect(subject).not_to be_valid }
|
25
|
+
it { expect(subject.errors.full_messages).to eql ['Emotional can\'t be blank', 'Emotional is invalid'] }
|
26
26
|
end
|
27
27
|
|
28
28
|
describe :validate_presence_of_emotive do
|
29
29
|
subject { Emotion.new(emotion: 'happy', emotional: User.create) }
|
30
30
|
before { subject.valid? }
|
31
31
|
|
32
|
-
it {
|
33
|
-
it { expect(subject.errors.full_messages).to eql [
|
32
|
+
it { expect(subject).not_to be_valid }
|
33
|
+
it { expect(subject.errors.full_messages).to eql ['Emotive can\'t be blank', 'Emotive is invalid'] }
|
34
34
|
end
|
35
35
|
|
36
36
|
describe :validate_inclusion_of_emotion do
|
37
37
|
subject { Emotion.new(emotion: 'mad', emotional: User.create, emotive: Picture.create) }
|
38
38
|
before { subject.valid? }
|
39
39
|
|
40
|
-
it {
|
41
|
-
it { expect(subject.errors.full_messages).to eql [
|
40
|
+
it { expect(subject).not_to be_valid }
|
41
|
+
it { expect(subject.errors.full_messages).to eql ['Emotion is invalid'] }
|
42
42
|
end
|
43
43
|
|
44
44
|
describe :validate_class_of_emotive do
|
45
45
|
subject { Emotion.new(emotion: 'happy', emotional: User.create, emotive: User.create) }
|
46
46
|
before { subject.valid? }
|
47
47
|
|
48
|
-
it {
|
49
|
-
it { expect(subject.errors.full_messages).to eql [
|
48
|
+
it { expect(subject).not_to be_valid }
|
49
|
+
it { expect(subject.errors.full_messages).to eql ['Emotive is invalid'] }
|
50
50
|
end
|
51
51
|
|
52
52
|
describe :validate_class_of_emotional do
|
53
53
|
subject { Emotion.new(emotion: 'happy', emotional: Picture.create, emotive: Picture.create) }
|
54
54
|
before { subject.valid? }
|
55
55
|
|
56
|
-
it {
|
57
|
-
it { expect(subject.errors.full_messages).to eql [
|
56
|
+
it { expect(subject).not_to be_valid }
|
57
|
+
it { expect(subject.errors.full_messages).to eql ['Emotional is invalid'] }
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -65,9 +65,9 @@ describe Emotions::Emotion do
|
|
65
65
|
let(:emotion) { Emotion.new(emotion: 'happy', emotional: user, emotive: picture) }
|
66
66
|
|
67
67
|
before do
|
68
|
-
picture.
|
69
|
-
user.
|
70
|
-
emotion.
|
68
|
+
expect(picture).to receive(:update_emotion_counter).with('happy').once
|
69
|
+
expect(user).to receive(:update_emotion_counter).with('happy').once
|
70
|
+
expect(emotion).to receive(:update_emotion_counter).once.and_call_original
|
71
71
|
end
|
72
72
|
|
73
73
|
it { emotion.save! }
|
@@ -80,9 +80,9 @@ describe Emotions::Emotion do
|
|
80
80
|
|
81
81
|
before do
|
82
82
|
emotion.save!
|
83
|
-
picture.
|
84
|
-
user.
|
85
|
-
emotion.
|
83
|
+
expect(picture).to receive(:update_emotion_counter).with('happy').once
|
84
|
+
expect(user).to receive(:update_emotion_counter).with('happy').once
|
85
|
+
expect(emotion).to receive(:update_emotion_counter).once.and_call_original
|
86
86
|
end
|
87
87
|
|
88
88
|
it { emotion.destroy }
|
@@ -22,23 +22,23 @@ describe Emotions::Emotional do
|
|
22
22
|
describe :Aliases do
|
23
23
|
subject { user }
|
24
24
|
|
25
|
-
it {
|
25
|
+
it { expect(subject).to respond_to :happy? }
|
26
26
|
|
27
|
-
it {
|
28
|
-
it {
|
29
|
-
it {
|
27
|
+
it { expect(subject).to respond_to :happy_about? }
|
28
|
+
it { expect(subject).to respond_to :happy_with? }
|
29
|
+
it { expect(subject).to respond_to :happy_over? }
|
30
30
|
|
31
|
-
it {
|
32
|
-
it {
|
33
|
-
it {
|
31
|
+
it { expect(subject).to respond_to :happy_about! }
|
32
|
+
it { expect(subject).to respond_to :happy_with! }
|
33
|
+
it { expect(subject).to respond_to :happy_over! }
|
34
34
|
|
35
|
-
it {
|
36
|
-
it {
|
37
|
-
it {
|
35
|
+
it { expect(subject).to respond_to :no_longer_happy_about! }
|
36
|
+
it { expect(subject).to respond_to :no_longer_happy_with! }
|
37
|
+
it { expect(subject).to respond_to :no_longer_happy_over! }
|
38
38
|
|
39
|
-
it {
|
40
|
-
it {
|
41
|
-
it {
|
39
|
+
it { expect(subject).to respond_to :happy_about }
|
40
|
+
it { expect(subject).to respond_to :happy_with }
|
41
|
+
it { expect(subject).to respond_to :happy_over }
|
42
42
|
end
|
43
43
|
|
44
44
|
describe :emotions_about do
|
@@ -59,7 +59,7 @@ describe Emotions::Emotional do
|
|
59
59
|
|
60
60
|
context 'for invalid emotive' do
|
61
61
|
it { expect(user.emotions_about(user)).to be_empty }
|
62
|
-
it { expect{ user.emotions_about(user) }.to_not raise_error }
|
62
|
+
it { expect { user.emotions_about(user) }.to_not raise_error }
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -67,16 +67,16 @@ describe Emotions::Emotional do
|
|
67
67
|
let(:picture) { Picture.create }
|
68
68
|
|
69
69
|
context 'with valid emotive and emotion' do
|
70
|
-
it { expect{ user.express! :happy, picture }.to change{ Emotion.count }.from(0).to(1) }
|
71
|
-
it { expect{ user.express! :happy, picture }.to change{ user.happy_about? picture }.from(false).to(true) }
|
70
|
+
it { expect { user.express! :happy, picture }.to change { Emotion.count }.from(0).to(1) }
|
71
|
+
it { expect { user.express! :happy, picture }.to change { user.happy_about? picture }.from(false).to(true) }
|
72
72
|
end
|
73
73
|
|
74
74
|
context 'with invalid emotive' do
|
75
|
-
it { expect{ user.express! :happy, user }.to raise_error(Emotions::InvalidEmotion) }
|
75
|
+
it { expect { user.express! :happy, user }.to raise_error(Emotions::InvalidEmotion) }
|
76
76
|
end
|
77
77
|
|
78
78
|
context 'with invalid emotion' do
|
79
|
-
it { expect{ user.express! :mad, picture }.to raise_error(Emotions::InvalidEmotion) }
|
79
|
+
it { expect { user.express! :mad, picture }.to raise_error(Emotions::InvalidEmotion) }
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -85,16 +85,30 @@ describe Emotions::Emotional do
|
|
85
85
|
before { user.happy_about!(picture) }
|
86
86
|
|
87
87
|
context 'with valid emotive and emotion' do
|
88
|
-
it { expect{ user.no_longer_express! :happy, picture }.to change{ Emotion.count }.from(1).to(0) }
|
89
|
-
it { expect{ user.no_longer_express! :happy, picture }.to change{ user.happy_about? picture }.from(true).to(false) }
|
88
|
+
it { expect { user.no_longer_express! :happy, picture }.to change { Emotion.count }.from(1).to(0) }
|
89
|
+
it { expect { user.no_longer_express! :happy, picture }.to change { user.happy_about? picture }.from(true).to(false) }
|
90
90
|
end
|
91
91
|
|
92
92
|
context 'with invalid emotive' do
|
93
|
-
it { expect{ user.no_longer_express! :happy, user }.to_not raise_error }
|
93
|
+
it { expect { user.no_longer_express! :happy, user }.to_not raise_error }
|
94
94
|
end
|
95
95
|
|
96
96
|
context 'with invalid emotion' do
|
97
|
-
it { expect{ user.no_longer_express! :mad, user }.to_not raise_error }
|
97
|
+
it { expect { user.no_longer_express! :mad, user }.to_not raise_error }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe :express? do
|
102
|
+
let(:picture) { Picture.create }
|
103
|
+
|
104
|
+
context 'when expressed' do
|
105
|
+
before { user.happy_about!(picture) }
|
106
|
+
|
107
|
+
it { expect(user.express? :happy, picture).to be_truthy }
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'when not expressed' do
|
111
|
+
it { expect(user.express? :happy, picture).to be_falsey }
|
98
112
|
end
|
99
113
|
end
|
100
114
|
|
@@ -105,12 +119,12 @@ describe Emotions::Emotional do
|
|
105
119
|
let(:other_picture) { Picture.create }
|
106
120
|
|
107
121
|
context 'with valid emotive' do
|
108
|
-
it { expect(user.happy_about? picture).to
|
109
|
-
it { expect(user.happy_about? other_picture).to
|
122
|
+
it { expect(user.happy_about? picture).to be_truthy }
|
123
|
+
it { expect(user.happy_about? other_picture).to be_falsey }
|
110
124
|
end
|
111
125
|
|
112
126
|
context 'with invalid emotive' do
|
113
|
-
it { expect{ user.happy_about? user }.to_not raise_error }
|
127
|
+
it { expect { user.happy_about? user }.to_not raise_error }
|
114
128
|
end
|
115
129
|
end
|
116
130
|
|
@@ -118,12 +132,12 @@ describe Emotions::Emotional do
|
|
118
132
|
let(:picture) { Picture.create }
|
119
133
|
|
120
134
|
context 'with valid emotive' do
|
121
|
-
it { expect{ user.happy_about! picture }.to change{ Emotion.count }.from(0).to(1) }
|
122
|
-
it { expect{ user.happy_about! picture }.to change{ user.happy_about? picture }.from(false).to(true) }
|
135
|
+
it { expect { user.happy_about! picture }.to change { Emotion.count }.from(0).to(1) }
|
136
|
+
it { expect { user.happy_about! picture }.to change { user.happy_about? picture }.from(false).to(true) }
|
123
137
|
end
|
124
138
|
|
125
139
|
context 'with invalid emotive' do
|
126
|
-
it { expect{ user.happy_about! user }.to raise_error(Emotions::InvalidEmotion) }
|
140
|
+
it { expect { user.happy_about! user }.to raise_error(Emotions::InvalidEmotion) }
|
127
141
|
end
|
128
142
|
end
|
129
143
|
|
@@ -132,24 +146,22 @@ describe Emotions::Emotional do
|
|
132
146
|
let(:picture) { Picture.create }
|
133
147
|
|
134
148
|
context 'with valid emotive' do
|
135
|
-
it { expect{ user.no_longer_happy_about! picture }.to change{ Emotion.count }.from(1).to(0) }
|
136
|
-
it { expect{ user.no_longer_happy_about! picture }.to change{ user.happy_about? picture }.from(true).to(false) }
|
149
|
+
it { expect { user.no_longer_happy_about! picture }.to change { Emotion.count }.from(1).to(0) }
|
150
|
+
it { expect { user.no_longer_happy_about! picture }.to change { user.happy_about? picture }.from(true).to(false) }
|
137
151
|
end
|
138
152
|
|
139
153
|
context 'with invalid emotive' do
|
140
154
|
it { expect(user.no_longer_happy_about! user).to be_nil }
|
141
|
-
it { expect{ user.no_longer_happy_about! user }.to_not raise_error }
|
155
|
+
it { expect { user.no_longer_happy_about! user }.to_not raise_error }
|
142
156
|
end
|
143
157
|
end
|
144
158
|
|
145
159
|
describe :update_emotion_counter do
|
146
160
|
let(:user) { User.create }
|
147
|
-
let(:relation)
|
148
|
-
double.tap { |double| double.stub(:count).and_return(42) }
|
149
|
-
end
|
161
|
+
let(:relation) { double(count: 42) }
|
150
162
|
|
151
163
|
before do
|
152
|
-
User.
|
164
|
+
allow_any_instance_of(User).to receive(:happy_about).and_return(relation)
|
153
165
|
user.update_emotion_counter(:happy)
|
154
166
|
end
|
155
167
|
|
@@ -162,9 +174,9 @@ describe Emotions::Emotional do
|
|
162
174
|
describe :Aliases do
|
163
175
|
subject { user.class }
|
164
176
|
|
165
|
-
it {
|
166
|
-
it {
|
167
|
-
it {
|
177
|
+
it { expect(subject).to respond_to :happy_about }
|
178
|
+
it { expect(subject).to respond_to :happy_with }
|
179
|
+
it { expect(subject).to respond_to :happy_over }
|
168
180
|
end
|
169
181
|
|
170
182
|
describe :DynamicMethods do
|
@@ -185,7 +197,7 @@ describe Emotions::Emotional do
|
|
185
197
|
|
186
198
|
context 'with invalid emotive' do
|
187
199
|
it { expect(User.happy_about(user).to_a).to be_empty }
|
188
|
-
it { expect{ User.happy_about(user).to_a }.to_not raise_error }
|
200
|
+
it { expect { User.happy_about(user).to_a }.to_not raise_error }
|
189
201
|
end
|
190
202
|
end
|
191
203
|
end
|
@@ -20,12 +20,10 @@ describe Emotions::Emotive do
|
|
20
20
|
|
21
21
|
describe :InstanceMethods do
|
22
22
|
describe :update_emotion_counter do
|
23
|
-
let(:relation)
|
24
|
-
double.tap { |double| double.stub(:count).and_return(42) }
|
25
|
-
end
|
23
|
+
let(:relation) { double(count: 42) }
|
26
24
|
|
27
25
|
before do
|
28
|
-
Picture.
|
26
|
+
allow_any_instance_of(Picture).to receive(:happy_about).and_return(relation)
|
29
27
|
picture.update_emotion_counter(:happy)
|
30
28
|
end
|
31
29
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
2
|
|
3
3
|
require 'rspec'
|
4
4
|
require 'sqlite3'
|
@@ -16,6 +16,11 @@ RSpec.configure do |config|
|
|
16
16
|
config.include DatabaseMacros
|
17
17
|
config.include ModelMacros
|
18
18
|
|
19
|
+
# Disable `should` syntax
|
20
|
+
config.expect_with :rspec do |c|
|
21
|
+
c.syntax = :expect
|
22
|
+
end
|
23
|
+
|
19
24
|
config.before(:each) do
|
20
25
|
# Create the SQLite database
|
21
26
|
setup_database
|
@@ -5,7 +5,7 @@ module DatabaseMacros
|
|
5
5
|
klass = Class.new(ActiveRecord::Migration)
|
6
6
|
|
7
7
|
# Create a new `up` that executes the argument
|
8
|
-
klass.send(:define_method, :up) {
|
8
|
+
klass.send(:define_method, :up) { instance_exec(&block) }
|
9
9
|
|
10
10
|
# Create a new instance of it and execute its `up` method
|
11
11
|
klass.new.up
|
@@ -28,7 +28,7 @@ module DatabaseMacros
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def cleanup_database
|
31
|
-
FileUtils.rm(DatabaseMacros.database_file) if File.
|
31
|
+
FileUtils.rm(DatabaseMacros.database_file) if File.exist?(DatabaseMacros.database_file)
|
32
32
|
end
|
33
33
|
|
34
34
|
# Run the built-in migration
|
metadata
CHANGED
@@ -1,85 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emotions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rémi Prévost
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '3.1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '3.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sqlite3
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '1.3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: phare
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.7'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.7'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.31'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.31'
|
83
111
|
description: Emotions is a Ruby library that allows ActiveRecord records to express
|
84
112
|
(and hopefully store) emotions about other records.
|
85
113
|
email:
|
@@ -88,9 +116,10 @@ executables: []
|
|
88
116
|
extensions: []
|
89
117
|
extra_rdoc_files: []
|
90
118
|
files:
|
91
|
-
-
|
92
|
-
-
|
93
|
-
-
|
119
|
+
- .gitignore
|
120
|
+
- .rspec
|
121
|
+
- .rubocop.yml
|
122
|
+
- .travis.yml
|
94
123
|
- Gemfile
|
95
124
|
- LICENSE.md
|
96
125
|
- README.md
|
@@ -123,17 +152,17 @@ require_paths:
|
|
123
152
|
- lib
|
124
153
|
required_ruby_version: !ruby/object:Gem::Requirement
|
125
154
|
requirements:
|
126
|
-
- -
|
155
|
+
- - '>='
|
127
156
|
- !ruby/object:Gem::Version
|
128
157
|
version: '0'
|
129
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
159
|
requirements:
|
131
|
-
- -
|
160
|
+
- - '>='
|
132
161
|
- !ruby/object:Gem::Version
|
133
162
|
version: '0'
|
134
163
|
requirements: []
|
135
164
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.
|
165
|
+
rubygems_version: 2.0.14
|
137
166
|
signing_key:
|
138
167
|
specification_version: 4
|
139
168
|
summary: Emotions is a Ruby library that allows ActiveRecord records to express (and
|