streama 0.3.2 → 0.3.4
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/.gitignore +4 -0
- data/.travis.yml +2 -0
- data/Gemfile +2 -8
- data/Gemfile.lock +36 -32
- data/README.md +134 -0
- data/Rakefile +3 -43
- data/lib/streama.rb +7 -7
- data/lib/streama/activity.rb +51 -55
- data/lib/streama/actor.rb +18 -22
- data/lib/streama/definition.rb +2 -2
- data/lib/streama/definition_dsl.rb +8 -3
- data/lib/streama/version.rb +3 -0
- data/spec/app/models/activity.rb +21 -0
- data/spec/{support/models/listing.rb → app/models/album.rb} +1 -1
- data/spec/{support/models/enquiry.rb → app/models/photo.rb} +2 -2
- data/spec/{support → app}/models/user.rb +0 -0
- data/spec/lib/activity_spec.rb +41 -21
- data/spec/lib/actor_spec.rb +20 -29
- data/spec/lib/definition_dsl_spec.rb +7 -1
- data/spec/lib/definition_spec.rb +6 -6
- data/spec/spec_helper.rb +30 -10
- data/streama.gemspec +18 -68
- metadata +75 -87
- data/README.rdoc +0 -114
- data/VERSION +0 -1
- data/spec/support/models/activity.rb +0 -10
data/lib/streama/definition.rb
CHANGED
@@ -2,14 +2,14 @@ module Streama
|
|
2
2
|
|
3
3
|
class Definition
|
4
4
|
|
5
|
-
attr_reader :name, :actor, :object, :
|
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
|
-
@
|
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
|
-
:
|
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, :
|
30
|
+
data_methods :actor, :object, :target_object
|
26
31
|
|
27
32
|
end
|
28
33
|
|
@@ -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
|
File without changes
|
data/spec/lib/activity_spec.rb
CHANGED
@@ -2,37 +2,57 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Activity" do
|
4
4
|
|
5
|
-
let(:
|
6
|
-
let(:
|
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
|
9
|
+
describe ".activity" do
|
10
10
|
it "registers and return a valid definition" do
|
11
|
-
@definition = Activity.activity(:
|
11
|
+
@definition = Activity.activity(:test_activity) do
|
12
12
|
actor :user, :cache => [:full_name]
|
13
|
-
object :
|
14
|
-
|
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
|
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
|
-
|
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(:
|
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
|
67
|
+
describe ".publish" do
|
48
68
|
it "creates a new activity" do
|
49
|
-
activity = Activity.publish(:
|
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
|
74
|
+
describe "#refresh" do
|
55
75
|
|
56
76
|
before :each do
|
57
77
|
@user = user
|
58
|
-
@activity = Activity.publish(:
|
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
|
93
|
+
describe "#load_instance" do
|
74
94
|
|
75
95
|
before :each do
|
76
|
-
@activity = Activity.publish(:
|
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
|
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(:
|
109
|
+
@activity.load_instance(:target_object).should be_instance_of Album
|
90
110
|
end
|
91
111
|
|
92
112
|
end
|
data/spec/lib/actor_spec.rb
CHANGED
@@ -1,54 +1,45 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Actor" do
|
4
|
-
|
5
|
-
let(:
|
6
|
-
let(:
|
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
|
-
|
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(:
|
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(:
|
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
|
-
|
39
|
-
user.publish_activity(:
|
40
|
-
user.publish_activity(:new_comment, :object =>
|
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 => :
|
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[:
|
39
|
+
dsl.attributes[:target_object].should eq :company => { :cache=>[:id, :name] }
|
34
40
|
end
|
35
41
|
|
36
42
|
end
|
data/spec/lib/definition_spec.rb
CHANGED
@@ -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(:
|
6
|
+
dsl = Streama::DefinitionDSL.new(:new_photo)
|
7
7
|
dsl.actor(:user, :cache => [:id, :full_name])
|
8
|
-
dsl.object(:
|
9
|
-
dsl.
|
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?(:
|
23
|
+
@definition.object.has_key?(:photo).should be true
|
24
24
|
end
|
25
25
|
|
26
26
|
it "assigns @target" do
|
27
|
-
@definition.
|
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(:
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -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
|
-
|
9
|
-
|
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
|
-
|
14
|
-
|
15
|
-
config.master =
|
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
|
-
|
23
|
-
|
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
|
data/streama.gemspec
CHANGED
@@ -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
|
8
|
-
s.version
|
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.
|
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
|
-
|
52
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|