• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

While creating AR extending plugin, I had some trouble to test it. Because testing a such plugin needs creating db and its absurd. So here's my solution. 

Tip #1: First, extend the AR, and name it as a MockBase. Then extend MockBase to test your class. This prevents other tests like your rails app or other plugins from failing.

Tip #2. Requiring environment.rb loads all rails env this includes AR. Thus you can you use AR in your test class.

   1  #acts_as_notifiable_test.rb
   2  begin
   3    require File.dirname(__FILE__) + '/../../../../config/environment'
   4  rescue LoadError
   5    require 'rubygems'
   6    gem 'activerecord'
   7    require 'active_record'
   8  end
   9  
  10  class MockBase < ActiveRecord::Base; end
  11  MockBase.class_eval do
  12    alias_method :save, :valid?
  13    def self.columns() @columns ||= []; end
  14  
  15    def self.column(name, sql_type = nil, default = nil, null = true)
  16      columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type, null)
  17    end
  18  end
  19  
  20  class MockModel < MockBase
  21    acts_as_notifiable :callback => :after_create, :message => "hello", :recipients => "test@gmail.com"
  22  end
  23  
  24  class ActsAsNotifiableTest < Test::Unit::TestCase
  25    def test_option_message_string
  26      assert_equal "hello", MockModel.new.instance_eval{jabber_message}
  27    end

Reference

posted by Png hibi on Thu 20 Mar 2008 at 23:58

Submitting new Issues via API would be so cool and meet the needs of the times. They have been issues about a year..., lame :(
Please please consider seriously!

posted by Png hibi on Fri 7 Mar 2008 at 12:26

In my company, we're using a Redmine. And I thought it would be more useful if I could receive some activities(Like creating/updating Issue) via GTalk. Thus I created acts_as_notifiable.

NOTE:

Repository

http://svn.s21g.com/public/rails/plugins/acts_as_notifiable/

To work with Redmine

  1. Install XMPP4R: http://xmpp4r.rubyforge.org/

       1  $sudo gem install xmpp4r
    

  2. Install plugin

  3. Create file: #{RAILS_ROOT}/config/acts_as_notifiable.yml
       1  #{RAILS_ROOT}/config/acts_as_notifiable.yml
       2  to:
       3    recipients: you@gmail.com me@gmail.com
       4  from:
       5    id: your_notify_account@gmail.com
       6    password: pass
       7    connect: talk.google.com
    
  4. Add acts_as_notifiable to the Model class
       1  class Issue
       2    acts_as_notifiable :message => Proc.new {|o| "[#{o.project.name}:#{o.class.name}##{o.id}]#{o.status.name}:#{o.subject}\n #{o.journals.last.notes unless o.journals.blank?}"}
    
  5. restart server

NOTE: Don't forget to add your_notify_account@gmail.com to your IM client!

posted by Png hibi on Wed 5 Mar 2008 at 16:54
Contents
How to mock ActiveRecord when testing your plugin
There is no API in Redmine at least now...
acts_as_notifiable: Rails plugin to send a notification via Jabber
Comments
satoko: In my app fail too. But authentication with yah... '08-5
or_use_the_provided_openid_nick: I can't get it to work! I get redirected to yah... '08-4
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ