diff --git a/MIT-LICENSE b/LICENSE similarity index 100% rename from MIT-LICENSE rename to LICENSE diff --git a/README.rdoc b/README.rdoc index 496f29f..dad2450 100644 --- a/README.rdoc +++ b/README.rdoc @@ -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 @@ -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 @@ -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 diff --git a/Rakefile b/Rakefile index c2c65aa..90fa0dc 100644 --- a/Rakefile +++ b/Rakefile @@ -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 = "james@giraffesoft.ca" - 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 diff --git a/VERSION.yml b/VERSION.yml deleted file mode 100644 index 3b60975..0000000 --- a/VERSION.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -:major: 0 -:minor: 4 -:patch: 1 diff --git a/generators/timeline_fu/templates/migration.rb b/generators/timeline_fu/templates/migration.rb index 316bded..2a5b6ac 100644 --- a/generators/timeline_fu/templates/migration.rb +++ b/generators/timeline_fu/templates/migration.rb @@ -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 - - diff --git a/lib/timeline_fu.rb b/lib/timeline_fu.rb index 125e179..b5bc712 100644 --- a/lib/timeline_fu.rb +++ b/lib/timeline_fu.rb @@ -1,6 +1,4 @@ require 'timeline_fu/fires' - -module TimelineFu -end +require 'timeline_fu/version' ActiveRecord::Base.send :include, TimelineFu::Fires diff --git a/lib/timeline_fu/macros.rb b/lib/timeline_fu/macros.rb index 9a200ef..d5cda44 100644 --- a/lib/timeline_fu/macros.rb +++ b/lib/timeline_fu/macros.rb @@ -3,7 +3,6 @@ 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 @@ -11,10 +10,8 @@ def should_fire_event(event_type, opts = {}) 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 diff --git a/lib/timeline_fu/matchers.rb b/lib/timeline_fu/matchers.rb index a2536c1..d11c0a5 100644 --- a/lib/timeline_fu/matchers.rb +++ b/lib/timeline_fu/matchers.rb @@ -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 @@ -38,7 +26,7 @@ def description end def expectation - expected = "#{@subject.name} to #{description}" + expected = "#{@subject.class.name} to #{description}" end def failure_message @@ -48,7 +36,6 @@ def failure_message def negative_failure_message "Did not expect #{expectation}" end - end def fire_event(event_type, opts) diff --git a/lib/timeline_fu/version.rb b/lib/timeline_fu/version.rb new file mode 100644 index 0000000..90dfa9c --- /dev/null +++ b/lib/timeline_fu/version.rb @@ -0,0 +1,3 @@ +module TimelineFu + VERSION = "0.4.2" +end diff --git a/test/fires_test.rb b/test/fires_test.rb index 3be36f6..50f1900 100644 --- a/test/fires_test.rb +++ b/test/fires_test.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 4312d2e..3b1aee6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,5 +1,5 @@ require 'rubygems' -require 'activerecord' +require 'active_record' require 'mocha' require 'test/unit' require 'logger' diff --git a/timeline_fu.gemspec b/timeline_fu.gemspec index 7b84709..1008222 100644 --- a/timeline_fu.gemspec +++ b/timeline_fu.gemspec @@ -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 = ["james@giraffesoft.ca"] + 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{james@giraffesoft.ca} - 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