streama 0.3.2 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,14 +2,14 @@ module Streama
2
2
 
3
3
  class Definition
4
4
 
5
- attr_reader :name, :actor, :object, :target, :receivers
5
+ attr_reader :name, :actor, :object, :target_object, :receivers
6
6
 
7
7
  # @param dsl [Streama::DefinitionDSL] A DSL object
8
8
  def initialize(definition)
9
9
  @name = definition[:name]
10
10
  @actor = definition[:actor] || {}
11
11
  @object = definition[:object] || {}
12
- @target = definition[:target] || {}
12
+ @target_object = definition[:target_object] || {}
13
13
  end
14
14
 
15
15
  #
@@ -9,12 +9,17 @@ module Streama
9
9
  :name => name.to_sym,
10
10
  :actor => {},
11
11
  :object => {},
12
- :target => {}
12
+ :target_object => {}
13
13
  }
14
14
  end
15
15
 
16
16
  delegate :[], :to => :@attributes
17
-
17
+
18
+ def target(*args)
19
+ warn "[DEPRECATION] #target is deprecated. Please use #target_object instead."
20
+ @attributes[:target_object].store(args[0].is_a?(Symbol) ? args[0] : args[0].class.to_sym, args[1])
21
+ end
22
+
18
23
  def self.data_methods(*args)
19
24
  args.each do |method|
20
25
  define_method method do |*args|
@@ -22,7 +27,7 @@ module Streama
22
27
  end
23
28
  end
24
29
  end
25
- data_methods :actor, :object, :target
30
+ data_methods :actor, :object, :target_object
26
31
 
27
32
  end
28
33
 
@@ -0,0 +1,3 @@
1
+ module Streama
2
+ VERSION = "0.3.4"
3
+ end
@@ -0,0 +1,21 @@
1
+ class Activity
2
+ include Streama::Activity
3
+
4
+ activity :new_photo do
5
+ actor :user, :cache => [:full_name]
6
+ object :photo, :cache => [:file]
7
+ target_object :album, :cache => [:title]
8
+ end
9
+
10
+ activity :new_photo_without_cache do
11
+ actor :user
12
+ object :photo
13
+ target_object :album
14
+ end
15
+
16
+ activity :new_comment do
17
+ actor :user, :cache => [:full_name]
18
+ object :photo
19
+ end
20
+
21
+ end
@@ -1,4 +1,4 @@
1
- class Listing
1
+ class Album
2
2
  include Mongoid::Document
3
3
 
4
4
  field :title
@@ -1,6 +1,6 @@
1
- class Enquiry
1
+ class Photo
2
2
  include Mongoid::Document
3
3
 
4
- field :comment
4
+ field :file
5
5
 
6
6
  end
File without changes
@@ -2,37 +2,57 @@ require 'spec_helper'
2
2
 
3
3
  describe "Activity" do
4
4
 
5
- let(:enquiry) { Enquiry.create(:comment => "I'm interested") }
6
- let(:listing) { Listing.create(:title => "A test listing") }
5
+ let(:photo) { Photo.create(:file => "image.jpg") }
6
+ let(:album) { Album.create(:title => "A test album") }
7
7
  let(:user) { User.create(:full_name => "Christos") }
8
8
 
9
- describe '.activity' do
9
+ describe ".activity" do
10
10
  it "registers and return a valid definition" do
11
- @definition = Activity.activity(:new_enquiry) do
11
+ @definition = Activity.activity(:test_activity) do
12
12
  actor :user, :cache => [:full_name]
13
- object :enquiry, :cache => [:comment]
14
- object :listing, :cache => [:title, :full_address]
15
- target :listing, :cache => [:title]
13
+ object :photo, :cache => [:file]
14
+ target_object :album, :cache => [:title]
16
15
  end
17
16
 
18
17
  @definition.is_a?(Streama::Definition).should be true
19
18
  end
19
+
20
20
  end
21
21
 
22
- describe '#publish' do
22
+ describe "#publish" do
23
+
24
+ before :each do
25
+ @send_to = []
26
+ 2.times { |n| @send_to << User.create(:full_name => "Custom Receiver #{n}") }
27
+ 5.times { |n| User.create(:full_name => "Receiver #{n}") }
28
+ end
29
+
30
+ it "pushes activity to receivers" do
31
+ @activity = Activity.publish(:new_photo, {:actor => user, :object => photo, :target_object => album, :receivers => @send_to})
32
+ @activity.receivers.size.should == 2
33
+ end
34
+
35
+
36
+ context "when activity not cached" do
37
+
38
+ it "pushes activity to receivers" do
39
+ @activity = Activity.publish(:new_photo_without_cache, {:actor => user, :object => photo, :target_object => album, :receivers => @send_to})
40
+ @activity.receivers.size.should == 2
41
+ end
42
+
43
+ end
23
44
 
24
45
  it "overrides the recievers if option passed" do
25
- send_to = []
26
- 2.times { |n| send_to << User.create(:full_name => "Custom Receiver #{n}") }
27
- 5.times { |n| User.create(:full_name => "Receiver #{n}") }
28
- @activity = Activity.publish(:new_enquiry, {:actor => user, :object => enquiry, :target => listing, :receivers => send_to})
46
+ @activity = Activity.publish(:new_photo, {:actor => user, :object => photo, :target_object => album, :receivers => @send_to})
29
47
  @activity.receivers.size.should == 2
30
48
  end
31
49
 
50
+
51
+
32
52
  context "when republishing"
33
53
  before :each do
34
54
  @actor = user
35
- @activity = Activity.publish(:new_enquiry, {:actor => @actor, :object => enquiry, :target => listing})
55
+ @activity = Activity.publish(:new_photo, {:actor => @actor, :object => photo, :target_object => album})
36
56
  @activity.publish
37
57
  end
38
58
 
@@ -44,18 +64,18 @@ describe "Activity" do
44
64
  end
45
65
  end
46
66
 
47
- describe '.publish' do
67
+ describe ".publish" do
48
68
  it "creates a new activity" do
49
- activity = Activity.publish(:new_enquiry, {:actor => user, :object => enquiry, :target => listing})
69
+ activity = Activity.publish(:new_photo, {:actor => user, :object => photo, :target_object => album})
50
70
  activity.should be_an_instance_of Activity
51
71
  end
52
72
  end
53
73
 
54
- describe '#refresh' do
74
+ describe "#refresh" do
55
75
 
56
76
  before :each do
57
77
  @user = user
58
- @activity = Activity.publish(:new_enquiry, {:actor => @user, :object => enquiry, :target => listing})
78
+ @activity = Activity.publish(:new_photo, {:actor => @user, :object => photo, :target_object => album})
59
79
  end
60
80
 
61
81
  it "reloads instances and updates activities stored data" do
@@ -70,10 +90,10 @@ describe "Activity" do
70
90
 
71
91
  end
72
92
 
73
- describe '#load_instance' do
93
+ describe "#load_instance" do
74
94
 
75
95
  before :each do
76
- @activity = Activity.publish(:new_enquiry, {:actor => user, :object => enquiry, :target => listing})
96
+ @activity = Activity.publish(:new_photo, {:actor => user, :object => photo, :target_object => album})
77
97
  @activity = Activity.last
78
98
  end
79
99
 
@@ -82,11 +102,11 @@ describe "Activity" do
82
102
  end
83
103
 
84
104
  it "loads an object instance" do
85
- @activity.load_instance(:object).should be_instance_of Enquiry
105
+ @activity.load_instance(:object).should be_instance_of Photo
86
106
  end
87
107
 
88
108
  it "loads a target instance" do
89
- @activity.load_instance(:target).should be_instance_of Listing
109
+ @activity.load_instance(:target_object).should be_instance_of Album
90
110
  end
91
111
 
92
112
  end
@@ -1,54 +1,45 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Actor" do
4
-
5
- let(:enquiry) { Enquiry.create(:comment => "I'm interested") }
6
- let(:listing) { Listing.create(:title => "A test listing") }
4
+
5
+ let(:photo) { Photo.create(:comment => "I'm interested") }
6
+ let(:album) { Album.create(:title => "A test album") }
7
7
  let(:user) { User.create(:full_name => "Christos") }
8
-
9
- before :all do
10
- Activity.activity :new_comment do
11
- actor :user, :cache => [:full_name]
12
- object :listing, :cache => [:title]
13
- target :listing, :cache => [:title]
14
- end
15
- end
16
-
8
+
17
9
  describe "#publish_activity" do
18
-
19
10
  before :each do
20
- 5.times { |n| User.create(:full_name => "Receiver #{n}") }
11
+ 2.times { |n| User.create(:full_name => "Receiver #{n}") }
21
12
  end
22
-
13
+
23
14
  it "pushes activity to receivers" do
24
- activity = user.publish_activity(:new_enquiry, :object => enquiry, :target => listing)
15
+ activity = user.publish_activity(:new_photo, :object => photo, :target_object => album)
25
16
  activity.receivers.size == 6
26
17
  end
27
-
18
+
28
19
  it "pushes to a defined stream" do
29
- activity = user.publish_activity(:new_enquiry, :object => enquiry, :target => listing, :receivers => :friends)
20
+ activity = user.publish_activity(:new_photo, :object => photo, :target_object => album, :receivers => :friends)
30
21
  activity.receivers.size == 6
31
22
  end
32
23
 
33
24
  end
34
-
25
+
35
26
  describe "#activity_stream" do
36
27
 
37
28
  before :each do
38
- 5.times { |n| User.create(:full_name => "Receiver #{n}") }
39
- user.publish_activity(:new_enquiry, :object => enquiry, :target => listing)
40
- user.publish_activity(:new_comment, :object => listing)
29
+ 2.times { |n| User.create(:full_name => "Receiver #{n}") }
30
+ user.publish_activity(:new_photo, :object => photo, :target_object => album)
31
+ user.publish_activity(:new_comment, :object => photo)
41
32
  end
42
-
33
+
43
34
  it "retrieves the stream for an actor" do
44
35
  user.activity_stream.size.should eq 2
45
36
  end
46
-
37
+
47
38
  it "retrieves the stream and filters to a particular activity type" do
48
- user.activity_stream(:type => :new_comment).size.should eq 1
39
+ user.activity_stream(:type => :new_photo).size.should eq 1
49
40
  end
50
-
41
+
51
42
  end
52
-
53
-
54
- end
43
+
44
+
45
+ end
@@ -28,9 +28,15 @@ describe "Definition" do
28
28
  end
29
29
 
30
30
  it "adds a target to the definition" do
31
+ dsl = definition_dsl
32
+ dsl.target_object(:company, :cache => [:id, :name])
33
+ dsl.attributes[:target_object].should eq :company => { :cache=>[:id, :name] }
34
+ end
35
+
36
+ it "deprecates target method" do
31
37
  dsl = definition_dsl
32
38
  dsl.target(:company, :cache => [:id, :name])
33
- dsl.attributes[:target].should eq :company => { :cache=>[:id, :name] }
39
+ dsl.attributes[:target_object].should eq :company => { :cache=>[:id, :name] }
34
40
  end
35
41
 
36
42
  end
@@ -3,10 +3,10 @@ require 'spec_helper'
3
3
  describe "Definition" do
4
4
 
5
5
  let(:definition_dsl) do
6
- dsl = Streama::DefinitionDSL.new(:new_enquiry)
6
+ dsl = Streama::DefinitionDSL.new(:new_photo)
7
7
  dsl.actor(:user, :cache => [:id, :full_name])
8
- dsl.object(:enquiry, :cache => [:id, :full_name])
9
- dsl.target(:listing, :cache => [:id, :name, :full_address])
8
+ dsl.object(:photo, :cache => [:id, :full_name])
9
+ dsl.target_object(:album, :cache => [:id, :name, :full_address])
10
10
  dsl
11
11
  end
12
12
 
@@ -20,11 +20,11 @@ describe "Definition" do
20
20
  @definition.actor.has_key?(:user).should be true
21
21
  end
22
22
  it "assigns @object" do
23
- @definition.object.has_key?(:enquiry).should be true
23
+ @definition.object.has_key?(:photo).should be true
24
24
  end
25
25
 
26
26
  it "assigns @target" do
27
- @definition.target.has_key?(:listing).should be true
27
+ @definition.target_object.has_key?(:album).should be true
28
28
  end
29
29
 
30
30
  end
@@ -53,7 +53,7 @@ describe "Definition" do
53
53
  describe '.find' do
54
54
 
55
55
  it "returns the definition by name" do
56
- Streama::Definition.find(:new_enquiry).name.should eq :new_enquiry
56
+ Streama::Definition.find(:new_photo).name.should eq :new_photo
57
57
  end
58
58
 
59
59
  it "raises an exception if invalid activity" do
@@ -1,25 +1,45 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
+
4
+ MODELS = File.join(File.dirname(__FILE__), "app/models")
5
+ SUPPORT = File.join(File.dirname(__FILE__), "support")
6
+ $LOAD_PATH.unshift(MODELS)
7
+ $LOAD_PATH.unshift(SUPPORT)
3
8
 
4
- require 'rspec'
5
9
  require 'streama'
6
10
  require 'mongoid'
11
+ require 'rspec'
7
12
 
8
- # Requires supporting files with custom matchers and macros, etc,
9
- # in ./support/ and its subdirectories.
10
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
13
+ LOGGER = Logger.new($stdout)
14
+ DATABASE_ID = Process.pid
11
15
 
12
16
  Mongoid.configure do |config|
13
- name = "streama-rspec-test"
14
- host = "localhost"
15
- config.master = Mongo::Connection.new.db(name)
17
+ database = Mongo::Connection.new.db("mongoid_#{DATABASE_ID}")
18
+ database.add_user("mongoid", "test")
19
+ config.master = database
20
+ config.logger = nil
21
+ end
22
+
23
+ Dir[ File.join(MODELS, "*.rb") ].sort.each do |file|
24
+ name = File.basename(file, ".rb")
25
+ autoload name.camelize.to_sym, name
26
+ end
27
+
28
+ Dir[ File.join(SUPPORT, "*.rb") ].each do |file|
29
+ require File.basename(file)
16
30
  end
17
31
 
18
32
  RSpec.configure do |config|
19
33
  config.include RSpec::Matchers
20
34
  config.include Mongoid::Matchers
21
35
  config.mock_with :rspec
22
- config.after :each do
23
- Mongoid.master.collections.select { |c| c.name != 'system.indexes' }.each(&:drop)
36
+
37
+ config.before(:each) do
38
+ Mongoid::IdentityMap.clear
39
+ end
40
+
41
+ config.after :suite do
42
+ Mongoid.master.connection.drop_database("mongoid_#{DATABASE_ID}")
24
43
  end
44
+
25
45
  end
@@ -1,75 +1,25 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "streama/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{streama}
8
- s.version = "0.3.2"
6
+ s.name = "streama"
7
+ s.version = Streama::VERSION
8
+ s.authors = ["Christos Pappas"]
9
+ s.email = ["christos.pappas@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Activity Streams for Mongoid}
12
+ s.description = %q{Streama is a simple activity stream gem for use with the Mongoid ODM framework}
9
13
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Christos Pappas"]
12
- s.date = %q{2011-06-29}
13
- s.description = %q{Streama is a simple activity stream gem for use with the Mongoid ODM framework.}
14
- s.email = %q{christos.pappas@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".rspec",
22
- "Gemfile",
23
- "Gemfile.lock",
24
- "LICENSE.txt",
25
- "README.rdoc",
26
- "Rakefile",
27
- "VERSION",
28
- "lib/streama.rb",
29
- "lib/streama/activity.rb",
30
- "lib/streama/actor.rb",
31
- "lib/streama/definition.rb",
32
- "lib/streama/definition_dsl.rb",
33
- "lib/streama/errors.rb",
34
- "spec/lib/activity_spec.rb",
35
- "spec/lib/actor_spec.rb",
36
- "spec/lib/definition_dsl_spec.rb",
37
- "spec/lib/definition_spec.rb",
38
- "spec/spec_helper.rb",
39
- "spec/support/models/activity.rb",
40
- "spec/support/models/enquiry.rb",
41
- "spec/support/models/listing.rb",
42
- "spec/support/models/user.rb",
43
- "streama.gemspec"
44
- ]
45
- s.homepage = %q{http://github.com/christospappas/streama}
46
- s.licenses = ["MIT"]
47
- s.require_paths = ["lib"]
48
- s.rubygems_version = %q{1.6.2}
49
- s.summary = %q{Streama is a simple activity stream gem for use with the Mongoid ODM framework.}
14
+ s.rubyforge_project = "streama"
50
15
 
51
- if s.respond_to? :specification_version then
52
- s.specification_version = 3
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
53
20
 
54
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
- s.add_runtime_dependency(%q<activesupport>, ["~> 3.0"])
56
- s.add_runtime_dependency(%q<mongoid>, ["~> 2.0"])
57
- s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
58
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
59
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.1"])
60
- else
61
- s.add_dependency(%q<activesupport>, ["~> 3.0"])
62
- s.add_dependency(%q<mongoid>, ["~> 2.0"])
63
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
64
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
- s.add_dependency(%q<jeweler>, ["~> 1.6.1"])
66
- end
67
- else
68
- s.add_dependency(%q<activesupport>, ["~> 3.0"])
69
- s.add_dependency(%q<mongoid>, ["~> 2.0"])
70
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
71
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
72
- s.add_dependency(%q<jeweler>, ["~> 1.6.1"])
73
- end
21
+ s.add_development_dependency "rspec", "~> 2.5"
22
+ s.add_development_dependency "mongoid", "~> 2.4"
23
+ s.add_development_dependency "bson_ext", "~> 1.5"
24
+ s.add_development_dependency "rake"
74
25
  end
75
-