trollo 0.1.0 → 0.1.1

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/lib/trollo/card.rb CHANGED
@@ -41,6 +41,20 @@ module Trollo
41
41
  self.save!
42
42
  end
43
43
 
44
+ def add_label(name)
45
+ return if has_label?(name)
46
+ label = Label.where(name: name).first || Label.create!(name: name)
47
+ self.labels << label
48
+ end
49
+
50
+ def remove_label(name)
51
+ self.labels -= Label.where(name: name)
52
+ end
53
+
54
+ def has_label?(name)
55
+ labels.map(&:name).include?(name)
56
+ end
57
+
44
58
  end
45
59
 
46
60
  end
data/lib/trollo/list.rb CHANGED
@@ -7,6 +7,20 @@ module Trollo
7
7
  has_and_belongs_to_many :labels, join_table: 'trollo_labels_lists'
8
8
  has_many :subscriptions, dependent: :destroy
9
9
  attr_accessible :name, :trollable
10
+
11
+ def add_label(name)
12
+ return if has_label?(name)
13
+ label = Label.where(name: name).first || Label.create!(name: name)
14
+ self.labels << label
15
+ end
16
+
17
+ def remove_label(name)
18
+ self.labels -= Label.where(name: name)
19
+ end
20
+
21
+ def has_label?(name)
22
+ labels.map(&:name).include?(name)
23
+ end
10
24
  end
11
25
 
12
26
  end
@@ -1,3 +1,3 @@
1
1
  module Trollo
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/trollo.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "active_record"
2
2
  require "workflow"
3
+ require "acts_as_commentable"
3
4
  require "trollo/version"
4
5
 
5
6
  module Trollo
@@ -2,12 +2,27 @@ require 'spec_helper'
2
2
 
3
3
  describe Trollo::Card do
4
4
 
5
- it "should support labels" do
5
+ it "can be labelled" do
6
6
  card = Trollo::Card.create!
7
- label = Trollo::Label.create! name: 'Bug'
7
+
8
+ expect{card.add_label('Bug')}.to change{Trollo::Label.count}.by(1)
9
+ expect{card.add_label('Bug')}.to change{Trollo::Label.count}.by(0)
10
+ expect{card.add_label('Bug')}.to change{card.labels.count}.by(0)
8
11
 
9
- card.labels << label
10
12
  card.labels.map(&:name).should == ['Bug']
11
13
  end
12
14
 
15
+ it "can have labels removed" do
16
+ card = Trollo::Card.create!
17
+
18
+ card.add_label('Bug')
19
+ card.add_label('Tree')
20
+ card.add_label('Foo')
21
+
22
+ expect{card.remove_label('Bug')}.to change{Trollo::Label.count}.by(0)
23
+ expect{card.remove_label('Tree')}.to change{card.labels.count}.by(-1)
24
+
25
+ card.labels.map(&:name).should == ['Foo']
26
+ end
27
+
13
28
  end
@@ -2,12 +2,27 @@ require 'spec_helper'
2
2
 
3
3
  describe Trollo::List do
4
4
 
5
- it "should support labels" do
5
+ it "can be labelled" do
6
6
  list = Trollo::List.create!
7
- label = Trollo::Label.create! name: 'Bug'
7
+
8
+ expect{list.add_label('Bug')}.to change{Trollo::Label.count}.by(1)
9
+ expect{list.add_label('Bug')}.to change{Trollo::Label.count}.by(0)
10
+ expect{list.add_label('Bug')}.to change{list.labels.count}.by(0)
8
11
 
9
- list.labels << label
10
12
  list.labels.map(&:name).should == ['Bug']
11
13
  end
12
14
 
15
+ it "can have labels removed" do
16
+ list = Trollo::List.create!
17
+
18
+ list.add_label('Bug')
19
+ list.add_label('Tree')
20
+ list.add_label('Foo')
21
+
22
+ expect{list.remove_label('Bug')}.to change{Trollo::Label.count}.by(0)
23
+ expect{list.remove_label('Tree')}.to change{list.labels.count}.by(-1)
24
+
25
+ list.labels.map(&:name).should == ['Foo']
26
+ end
27
+
13
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trollo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
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: 2014-01-16 00:00:00.000000000 Z
12
+ date: 2014-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport