extraextra 0.1.1 → 0.1.2

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/Gemfile CHANGED
@@ -8,4 +8,5 @@ gem "rake"
8
8
 
9
9
  group :test do
10
10
  gem "rspec"
11
+ gem "factory_girl"
11
12
  end
data/Gemfile.lock CHANGED
@@ -3,6 +3,7 @@ GEM
3
3
  specs:
4
4
  bson (1.0.7)
5
5
  bson_ext (1.0.7)
6
+ factory_girl (1.3.2)
6
7
  gemcutter (0.6.1)
7
8
  git (1.2.5)
8
9
  jeweler (1.4.0)
@@ -22,6 +23,7 @@ PLATFORMS
22
23
 
23
24
  DEPENDENCIES
24
25
  bson_ext
26
+ factory_girl
25
27
  jeweler
26
28
  mongo
27
29
  rake
data/README.rdoc CHANGED
@@ -56,15 +56,15 @@ This returns an array of Extra objects. To find out more about a particular
56
56
 
57
57
  $ extra = Extra::Extra::! :sports, user, "hit a home run!"
58
58
 
59
- $ extra.who?
59
+ $ extra.who
60
60
  => #<User:0x0000010089ea80>
61
- $ extra.what?
61
+ $ extra.what
62
62
  => "hit a home run"
63
- $ extra.where?
63
+ $ extra.where
64
64
  => nil # currently undecided
65
- $ extra.when?
65
+ $ extra.when
66
66
  => 1283311813
67
- $ extra.how?
67
+ $ extra.how
68
68
  => nil # currently undecided
69
69
  $ extra.to_s
70
70
  => "Steve hit a home run"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/extraextra.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{extraextra}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Steve Klabnik"]
@@ -14,7 +14,6 @@ Gem::Specification.new do |s|
14
14
  s.email = %q{steve@steveklabnik.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.md",
18
17
  "README.rdoc"
19
18
  ]
20
19
  s.files = [
@@ -23,7 +22,6 @@ Gem::Specification.new do |s|
23
22
  "Gemfile",
24
23
  "Gemfile.lock",
25
24
  "LICENSE",
26
- "README.md",
27
25
  "README.rdoc",
28
26
  "Rakefile",
29
27
  "VERSION",
@@ -31,6 +29,7 @@ Gem::Specification.new do |s|
31
29
  "lib/extra/extra.rb",
32
30
  "lib/extraextra.rb",
33
31
  "spec/extraextra_spec.rb",
32
+ "spec/factories/user.rb",
34
33
  "spec/spec.opts",
35
34
  "spec/spec_helper.rb",
36
35
  "test.rb"
@@ -42,6 +41,7 @@ Gem::Specification.new do |s|
42
41
  s.summary = %q{Super simple news feeds powered by MongoDB.}
43
42
  s.test_files = [
44
43
  "spec/extraextra_spec.rb",
44
+ "spec/factories/user.rb",
45
45
  "spec/spec_helper.rb"
46
46
  ]
47
47
 
data/lib/extra/extra.rb CHANGED
@@ -3,12 +3,29 @@ include Mongo
3
3
 
4
4
  module Extra
5
5
 
6
+ # Extra is the main class in Extra! Extra! It's what gets returned from
7
+ # queries, and is the main interface to the entire system.
6
8
  class Extra
7
9
 
10
+ attr_accessor :category,
11
+ :who_id,
12
+ :who_name,
13
+ :who_class,
14
+ :what,
15
+ :when
16
+
17
+ # For now, this is just a simple sentence describing what happened.
18
+ # We'll see if something more complex makes sense later.
19
+ def to_s
20
+ "#{who_name} #{what}"
21
+ end
8
22
 
9
23
  class << self
10
24
  attr_accessor :db, :collection
11
25
 
26
+ # The source method is used to set up the connection to MongoDB. Right now
27
+ # it has to be called by the user before doing anything else, which sucks.
28
+ # I'll probably add in something to make it autoconnect soon.
12
29
  def source opts={}
13
30
  opts[:host] ||= "localhost"
14
31
  opts[:port] ||= 27017
@@ -16,20 +33,29 @@ module Extra
16
33
  self.collection = db["extras"]
17
34
  end
18
35
 
36
+ # Extra::Extra.! is the method used to report what's going on. It takes a
37
+ # symbol for a category, the user who did whatever's newsworthy, and some
38
+ # text that describes what happened.
19
39
  def !(category, user, text)
20
- collection.insert category: category,
21
- who_id: user.id,
22
- who_name: user.username,
23
- who_class: user.class.to_s,
24
- what: text,
25
- when: Time.now.to_s
40
+
41
+ args = {
42
+ category: category,
43
+ who_id: user.id,
44
+ who_name: user.username,
45
+ who_class: user.class.to_s,
46
+ what: text,
47
+ when: Time.now.to_s
48
+ }
49
+ collection.insert args
50
+ Extra.new args
26
51
  end
27
52
 
53
+ # This method returns all Extras that are associated with a given person.
28
54
  def read_all_about_it user
29
55
 
30
56
  collection.find(who_id: user.id,
31
57
  who_class: user.class.to_s
32
- ).to_a
58
+ ).collect{|args| Extra.new args }
33
59
 
34
60
  end
35
61
  end
@@ -10,8 +10,8 @@ describe Extra::Extra do
10
10
  obj = mock("Connection")
11
11
  db = mock("db")
12
12
  db.should_receive(:[])
13
- obj.should_receive(:db).with("extraextra").and_return(db)
14
- Mongo::Connection.should_receive(:new).with("localhost", 1337).and_return(obj)
13
+ obj.should_receive(:db).with("extraextra").twice.and_return(db)
14
+ Mongo::Connection.should_receive(:new).twice.and_return(obj)
15
15
  Extra::Extra.should_receive(:db=).and_return(db)
16
16
  Extra::Extra.should_receive(:db).and_return(db)
17
17
 
@@ -39,14 +39,20 @@ describe Extra::Extra do
39
39
  end
40
40
 
41
41
  it "should return Extras for the user" do
42
- user = mock("User", :id => 1, :class => "User")
43
- extra = mock("Extra")
44
- collection = mock("collection")
45
- collection.should_receive(:find).with(:who_id=>1, :who_class=>"User").and_return([extra])
46
- Extra::Extra.should_receive(:collection).and_return(collection)
42
+ user = Factory(:user)
43
+ Extra::Extra.source
44
+ extra = Extra::Extra::! :breaking, user, "hit a home run"
47
45
 
48
46
  extras = Extra::Extra.read_all_about_it(user)
49
- extras.should == [extra]
47
+ extras.length.should == 1
48
+ ex = extras.first
49
+ ex.category.should == extra.category
50
+ ex.who_id.should == extra.who_id
51
+ ex.who_name.should == extra.who_name
52
+ ex.who_class.should == extra.who_class
53
+ ex.what.should == extra.what
54
+ ex.when.should == extra.when
55
+ ex.to_s.should == extra.to_s
50
56
  end
51
57
  end
52
58
  end
@@ -0,0 +1,13 @@
1
+ # we just want a dummy user
2
+ class User
3
+
4
+ def save!; end
5
+ def id=(id); end
6
+ def id; 1 end
7
+ def username=(username); end
8
+ def username; "steve" end
9
+
10
+ end
11
+
12
+ Factory.define :user do |u|
13
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,24 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'extraextra'
4
4
  require 'spec'
5
5
  require 'spec/autorun'
6
+ require 'factory_girl'
7
+
8
+ Dir.glob(File.join(File.dirname(__FILE__), '/factories/*.rb')).each do |factory|
9
+ require factory
10
+ end
11
+
6
12
 
7
13
  Spec::Runner.configure do |config|
14
+
15
+ config.mock_with :rspec
16
+
17
+ config.after(:each) do
18
+
19
+ db = Connection.new.db('extraextra')
20
+ unless db.class.to_s == "Spec::Mocks::Mock"
21
+ coll = db.collection('extras')
22
+ coll.remove
23
+ end
24
+ end
8
25
 
9
26
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Steve Klabnik
@@ -55,7 +55,6 @@ extensions: []
55
55
 
56
56
  extra_rdoc_files:
57
57
  - LICENSE
58
- - README.md
59
58
  - README.rdoc
60
59
  files:
61
60
  - .document
@@ -63,7 +62,6 @@ files:
63
62
  - Gemfile
64
63
  - Gemfile.lock
65
64
  - LICENSE
66
- - README.md
67
65
  - README.rdoc
68
66
  - Rakefile
69
67
  - VERSION
@@ -71,6 +69,7 @@ files:
71
69
  - lib/extra/extra.rb
72
70
  - lib/extraextra.rb
73
71
  - spec/extraextra_spec.rb
72
+ - spec/factories/user.rb
74
73
  - spec/spec.opts
75
74
  - spec/spec_helper.rb
76
75
  - test.rb
@@ -88,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
87
  requirements:
89
88
  - - ">="
90
89
  - !ruby/object:Gem::Version
91
- hash: -1570624595924975839
90
+ hash: 3599394924060512683
92
91
  segments:
93
92
  - 0
94
93
  version: "0"
@@ -109,4 +108,5 @@ specification_version: 3
109
108
  summary: Super simple news feeds powered by MongoDB.
110
109
  test_files:
111
110
  - spec/extraextra_spec.rb
111
+ - spec/factories/user.rb
112
112
  - spec/spec_helper.rb
data/README.md DELETED
@@ -1,107 +0,0 @@
1
- EXTRA! EXTRA! READ ALL ABOUT IT!
2
- ================================
3
-
4
- Need to add a news feed to your application? EXTRA! EXTRA! is just the Gem
5
- for you! This is a common need for many social applications. EXTRA! EXTRA!
6
- uses MongoDB to give you super fast, super convenient feeds.
7
-
8
- ## Quick Note ###############################################################
9
-
10
- Not all of this works yet. This is just a prerelease. README driven
11
- development FTW!
12
-
13
- ## Install ##################################################################
14
-
15
- EXTRA! EXTRA! will be distributed via Rubygems, so just
16
-
17
- $ gem install extraextra
18
-
19
- and you'll be reading the news in no time!
20
-
21
- ## Source ###################################################################
22
-
23
- The source of EXTRA! EXTRA! is on GitHub, and can be found here:
24
-
25
- http://github.com/steveklabnik/extraextra
26
-
27
- It can be cloned via
28
-
29
- $ git clone git://github.com/steveklabnik/extraextra.git
30
-
31
- ## Requirements #############################################################
32
-
33
- * **Ruby 1.9** Sorry for you 1.8 people, 1.9 is the current version of Ruby.
34
- * **mongo** If you're going to use MongoDB...
35
-
36
- ## Usage ####################################################################
37
-
38
- The first thing you'll need to do is configure EXTRA! EXTRA! to use your
39
- MongoDB installation.
40
-
41
- Extra::Extra.source :host => "localhost", :port => "1337"
42
-
43
- To record something newsworthy, just do this:
44
-
45
- $ Extra::Extra::! :breaking, user, "has just done something awesome!"
46
-
47
- To find out what interesting things a particular user has done:
48
-
49
- $ Extra::Extra.read_all_about_it user
50
-
51
- or
52
-
53
- $ Extra::Extra.the_scoop user
54
-
55
- This returns an array of Extra objects. To find out more about a particular
56
- Extra:
57
-
58
- $ extra = Extra::Extra::! :sports, user, "hit a home run!"
59
-
60
- $ extra.who?
61
- => #<User:0x0000010089ea80>
62
- $ extra.what?
63
- => "hit a home run"
64
- $ extra.where?
65
- => nil # currently undecided
66
- $ extra.when?
67
- => 1283311813
68
- $ extra.how?
69
- => nil # currently undecided
70
- $ extra.to_s
71
- => "Steve hit a home run"
72
-
73
- The name in to_s comes from user#username. If you use something else...
74
- I'll provide a way to override this eventually.
75
-
76
- To only see breaking news:
77
-
78
- $ user.breaking_news
79
-
80
- This will filter out only the news in the 'breaking' category.
81
-
82
- To find out what interesting things a users's friends have done:
83
-
84
- $ user.scope_the_scene
85
-
86
- To define what who you're friends with, make a method on your user model
87
- named my_peeps. For a (hypothetical) example:
88
-
89
- class User
90
- def my_peeps
91
- User.friends.collect(&:id)
92
- end
93
- end
94
-
95
- The my_peeps method should return an Array of ids. This method will be
96
- called during scope_the_scene to determine what results get returned.
97
-
98
- ## Contributing #############################################################
99
-
100
- Fork, commit, pull request. Bonus points for topic branches and great commit
101
- messages.
102
-
103
- In particular, I will accept most patches that add good aliases for methods.
104
-
105
- ## This is just a cleverly named logging framework ##########################
106
-
107
- No, it's not. Shut up.