Skip to content

Added indexes and fixed RSpec matcher. #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
26 changes: 19 additions & 7 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ Easily build timelines, much like GitHub's news feed.
TimelineFu requires you to have a TimelineEvent model.
The simplest way is to use the generator.

$ script/generate timeline_fu && rake db:migrate
$ rails generate timeline_fu && rake db:migrate
exists db/migrate
create db/migrate/20090333222034_create_timeline_events.rb
create app/models/timeline_event.rb
# Migration blabber...

Next step is to determine what generates an event in your various models.

class Post < ActiveRecord::Base
#...
belongs_to :author, :class_name => 'Person'
fires :new_post, :on => :create,
:actor => :author
fires :new_post, :on => :create, :actor => :author
end

You can add 'fires' statements to as many models as you want on as many models
Expand Down Expand Up @@ -47,12 +44,11 @@ The rest all fit neatly in an options hash.
Here's another example:

class Comment < ActiveRecord::Base
#...
belongs_to :commenter, :class_name => 'Person'
belongs_to :post
fires :new_comment, :on => :create,
:actor => :commenter,
#implicit :subject => self,
# implicit :subject => self,
:secondary_subject => 'post',
:if => lambda { |comment| comment.commenter != comment.post.author }
end
Expand Down Expand Up @@ -97,6 +93,22 @@ Contributions are welcome :-)
# Gemfile
gem "timeline_fu"

== Testing with RSpec

TimelineFu bundles a RSpec matcher to test models events.

require 'timeline_fu/matchers'

RSpec.configure do |config|
config.include TimelineFu::Matchers, :type => :model
end

Now you can use the +fire_event+ matcher on your specs.

describe Post do
it { should fire_event(:new_post, :on => :create) }
end

== License

Copyright (c) 2008 James Golick, released under the MIT license
40 changes: 13 additions & 27 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require "rake/testtask"
require "bundler/gem_tasks"
require "rake/rdoctask"

desc 'Default: run unit tests.'
desc "Default: run unit tests."
task :default => :test

desc 'Test the timeline_fu plugin.'
desc "Test the timeline_fu plugin."
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.libs << "lib"
t.pattern = "test/**/*_test.rb"
t.verbose = true
end

begin
require 'jeweler'
Jeweler::Tasks.new do |s|
s.name = "timeline_fu"
s.summary = %Q{Easily build timelines, much like GitHub's news feed}
s.email = "[email protected]"
s.homepage = "http://github.com/giraffesoft/timeline_fu"
s.description = "Easily build timelines, much like GitHub's news feed"
s.authors = ["James Golick", "Mathieu Martin", "Francois Beausoleil"]
end
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end

desc 'Generate documentation for the timeline_fu plugin.'
desc "Generate documentation for the timeline_fu plugin."
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'TimelineFu'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
rdoc.rdoc_dir = "rdoc"
rdoc.title = "TimelineFu"
rdoc.options << "--line-numbers" << "--inline-source"
rdoc.rdoc_files.include("README*")
rdoc.rdoc_files.include("lib/**/*.rb")
end
4 changes: 0 additions & 4 deletions VERSION.yml

This file was deleted.

5 changes: 3 additions & 2 deletions generators/timeline_fu/templates/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ def self.up
t.integer :subject_id, :actor_id, :secondary_subject_id
t.timestamps
end
add_index :timeline_events, [:subject_id, :subject_type]
add_index :timeline_events, [:actor_id, :actor_type]
add_index :timeline_events, [:secondary_subject_id , :secondary_subject_type], :name => 'secondary_subject_timeline_events'
end

def self.down
drop_table :timeline_events
end
end


4 changes: 1 addition & 3 deletions lib/timeline_fu.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
require 'timeline_fu/fires'

module TimelineFu
end
require 'timeline_fu/version'

ActiveRecord::Base.send :include, TimelineFu::Fires
3 changes: 0 additions & 3 deletions lib/timeline_fu/macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ module Macros
def should_fire_event(event_type, opts = {})
should "fire #{event_type} on #{opts[:on]}" do
matcher = fire_event(event_type, opts)

assert_accepts matcher, self.class.name.gsub(/Test$/, '').constantize
end
end

def should_not_fire_event(event_type, opts = {})
should "fire #{event_type} on #{opts[:on]}" do
matcher = fire_event(event_type, opts)

assert_rejects matcher, self.class.name.gsub(/Test$/, '').constantize
end
end

end
end
21 changes: 4 additions & 17 deletions lib/timeline_fu/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,14 @@ def initialize(event_type, opts = {})

def matches?(subject)
@subject = subject

defines_callback_method? && setups_up_callback?
defines_callback_method?
end

def defines_callback_method?
if @subject.instance_methods.include?(@method.to_s)
true
else
@missing = "#{@subject.name} does not respond to #{@method}"
false
end
end

def setups_up_callback?
callback_chain_name = "after_#{@opts[:on]}_callback_chain"
callback_chain = @subject.send(callback_chain_name)
if callback_chain.any? {|chain| chain.method == @method }
if @subject.methods.include?(@method)
true
else
@missing = "does setup after #{@opts[:on]} callback for #{@method}"
@missing = "#{@subject.class.name} instance does not respond to #{@method}"
false
end
end
Expand All @@ -38,7 +26,7 @@ def description
end

def expectation
expected = "#{@subject.name} to #{description}"
expected = "#{@subject.class.name} to #{description}"
end

def failure_message
Expand All @@ -48,7 +36,6 @@ def failure_message
def negative_failure_message
"Did not expect #{expectation}"
end

end

def fire_event(event_type, opts)
Expand Down
3 changes: 3 additions & 0 deletions lib/timeline_fu/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module TimelineFu
VERSION = "0.4.2"
end
2 changes: 1 addition & 1 deletion test/fires_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.dirname(__FILE__)+'/test_helper'
require File.expand_path(File.dirname(__FILE__)) + '/test_helper'

class FiresTest < Test::Unit::TestCase
def setup
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'rubygems'
require 'activerecord'
require 'active_record'
require 'mocha'
require 'test/unit'
require 'logger'
Expand Down
61 changes: 13 additions & 48 deletions timeline_fu.gemspec
Original file line number Diff line number Diff line change
@@ -1,55 +1,20 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "timeline_fu/version"

Gem::Specification.new do |s|
s.name = %q{timeline_fu}
s.version = "0.4.1"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["James Golick", "Mathieu Martin", "Francois Beausoleil"]
s.date = %q{2011-06-23}
s.name = "timeline_fu"
s.version = TimelineFu::VERSION
s.authors = ["James Golick", "Mathieu Martin", "Francois Beausoleil"]
s.email = ["[email protected]"]
s.homepage = "http://github.com/giraffesoft/timeline_fu"
s.summary = %q{Easily build timelines, much like GitHub's news feed}
s.description = %q{Easily build timelines, much like GitHub's news feed}
s.email = %q{[email protected]}
s.extra_rdoc_files = [
"README.rdoc"
]
s.files = [
".gitignore",
"MIT-LICENSE",
"README.rdoc",
"Rakefile",
"VERSION.yml",
"generators/timeline_fu/USAGE",
"generators/timeline_fu/templates/migration.rb",
"generators/timeline_fu/templates/model.rb",
"generators/timeline_fu/timeline_fu_generator.rb",
"init.rb",
"lib/timeline_fu.rb",
"lib/timeline_fu/fires.rb",
"lib/timeline_fu/macros.rb",
"lib/timeline_fu/matchers.rb",
"shoulda_macros/timeline_fu_shoulda.rb",
"test/fires_test.rb",
"test/test_helper.rb",
"timeline_fu.gemspec"
]
s.has_rdoc = true
s.homepage = %q{http://github.com/giraffesoft/timeline_fu}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.1}
s.summary = %q{Easily build timelines, much like GitHub's news feed}
s.test_files = [
"test/fires_test.rb",
"test/test_helper.rb"
]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 2
s.has_rdoc = true

if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
else
end
else
end
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
end