bustle 0.1.2 → 0.1.3

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/README.md CHANGED
@@ -125,7 +125,10 @@ Bustle::Publishers.add post
125
125
  #### Create a Subscription
126
126
 
127
127
  ```ruby
128
+ # returns a subscription instance upon duplicated entry
128
129
  Bustle::Subscriptions.add bustle_publisher, bustle_subscriber
130
+ # raises error upon duplicated entry
131
+ Bustle::Subscriptions.add! bustle_publisher, bustle_subscriber
129
132
 
130
133
  # example
131
134
  publisher = Bustle::Publishers.get(Post.first)
@@ -3,12 +3,6 @@ module Bustle::Concern
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module ClassMethods
6
- def add(resource)
7
- add!(resource)
8
- rescue
9
- get(resource)
10
- end
11
-
12
6
  def add!(resource)
13
7
  self::RESOURCE_NAME.constantize.to_adapter.create!(
14
8
  :resource_class => resource.class.name,
@@ -16,6 +10,12 @@ module Bustle::Concern
16
10
  )
17
11
  end
18
12
 
13
+ def add(resource)
14
+ add!(resource)
15
+ rescue
16
+ get(resource)
17
+ end
18
+
19
19
  def get(resource)
20
20
  self::RESOURCE_NAME.constantize.to_adapter.find_first(
21
21
  :resource_class => resource.class.name,
@@ -7,13 +7,19 @@ module Bustle
7
7
  include Concern::ForSubscriber
8
8
 
9
9
  class << self
10
- def add(publisher, subscriber)
10
+ def add!(publisher, subscriber)
11
11
  Subscription.to_adapter.create!(
12
12
  :publisher_id => publisher.id,
13
13
  :subscriber_id => subscriber.id
14
14
  )
15
15
  end
16
16
 
17
+ def add(publisher, subscriber)
18
+ add!(publisher, subscriber)
19
+ rescue
20
+ get(publisher, subscriber)
21
+ end
22
+
17
23
  def get(publisher, subscriber)
18
24
  Subscription.to_adapter.find_first(
19
25
  :publisher_id => publisher.id,
@@ -1,3 +1,3 @@
1
1
  module Bustle
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -20,6 +20,14 @@ module Bustle
20
20
  subscription.subscriber_id.should == subscriber.id
21
21
  end
22
22
 
23
+ it "gets a subscription if it already exists" do
24
+ Subscriptions.add(publisher, subscriber).should be_kind_of(Subscription)
25
+ end
26
+
27
+ it "gets a subscription if it already exists" do
28
+ expect { Subscriptions.add! publisher, subscriber }.to raise_error
29
+ end
30
+
23
31
  it "finds a subscription" do
24
32
  subscription = Subscriptions.get publisher, subscriber
25
33
 
@@ -1,5 +1,5 @@
1
1
  shared_examples 'resource_collection' do
2
- let(:resource_class) { described_class::RESOURCE_NAME.constantize.to_adapter }
2
+ let(:resource_class) { described_class::RESOURCE_NAME.constantize }
3
3
 
4
4
  context "#add" do
5
5
  it "adds a model record" do
@@ -8,11 +8,11 @@ shared_examples 'resource_collection' do
8
8
 
9
9
  it "gets the model if it already exists" do
10
10
  described_class.add(user)
11
- described_class.add(user).resource_class.should == 'Bustle::Dummy::User'
11
+ described_class.add(user).should be_kind_of(resource_class)
12
12
  end
13
13
 
14
14
  it "explicitly adds a model record" do
15
- described_class.add!(user).resource_class.should == 'Bustle::Dummy::User'
15
+ described_class.add!(user).should be_kind_of(resource_class)
16
16
  end
17
17
 
18
18
  it "raises error if the model already exists" do
@@ -27,7 +27,7 @@ shared_examples 'resource_collection' do
27
27
  end
28
28
 
29
29
  it "adds a model record" do
30
- model = resource_class.get(1)
30
+ model = resource_class.to_adapter.get(1)
31
31
  model.resource_class.should == 'Bustle::Dummy::User'
32
32
  model.resource_id.should == 42
33
33
  end
@@ -40,7 +40,7 @@ shared_examples 'resource_collection' do
40
40
 
41
41
  it "removes a model record" do
42
42
  described_class.remove(user)
43
- resource_class.find_all({}).count.should == 0
43
+ resource_class.to_adapter.find_all({}).count.should == 0
44
44
  end
45
45
  end
46
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bustle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -234,7 +234,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
234
234
  version: '0'
235
235
  segments:
236
236
  - 0
237
- hash: 1375749694743315937
237
+ hash: 2793893901465287910
238
238
  required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  none: false
240
240
  requirements:
@@ -243,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
243
  version: '0'
244
244
  segments:
245
245
  - 0
246
- hash: 1375749694743315937
246
+ hash: 2793893901465287910
247
247
  requirements: []
248
248
  rubyforge_project:
249
249
  rubygems_version: 1.8.24