This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

added shoulda tests, basic test for comments, etc.

  • Loading branch information...
Josh Adams
Josh Adams committed Apr 20, 2009
1 parent c415593 commit 5bd3c74f05589a41f4c917b047f6b033a4029ee5
@@ -54,6 +54,6 @@ def move_up
def move_down
@page_plugin.move_lower
flash[:notice] = "Plugin was moved down by one"
redirect_to edit_admin_page_path @page_plugin.page
redirect_to edit_admin_page_path(@page_plugin.page)
end
end
@@ -16,27 +16,20 @@

# This was copied from the acts_as_commentable plugin, and I'm changing it a bit - JA
class Comment < ActiveRecord::Base
validates_presence_of :commentable_type, :commentable_id, :comments

belongs_to :commentable, :polymorphic => true

# NOTE: Comments belong to a user
belongs_to :user

# NOTE: install the acts_as_votable plugin if you
# want user to vote on the quality of comments.
#acts_as_voteable

# NOTE: Comments belong to a user
belongs_to :user

named_scope :recent, :limit => 5, :order => "created_at DESC"
named_scope :for, lambda{ |klass| { :conditions => ["commentable_type = ?", klass] } }

# Helper class method to lookup all comments assigned
# to all commentable types for a given user.
def self.find_comments_by_user(user)
find(:all,
:conditions => ["user_id = ?", user.id],
:order => "created_at DESC"
)
end

# Helper class method to look up all comments for
# commentable class name and commentable id.
def self.find_comments_for_commentable(commentable_str, commentable_id)
@@ -52,9 +52,16 @@
:source => 'http://gems.github.com'

config.gem 'rubyist-aasm', :version => '~> 2.0.2', :lib => 'aasm', :source => "http://gems.github.com"
config.gem 'datanoise-actionwebservice', :lib => 'actionwebservice', :source => "http://gems.github.com"
config.gem 'datanoise-actionwebservice', :lib => 'actionwebservice', :source => "http://gems.github.com", :version => '~> 2.2.2'
config.gem 'mocha'

config.gem 'thoughtbot-shoulda', :lib => 'shoulda', :source => 'http://gems.github.com'
config.gem 'thoughtbot-factory_girl', :lib => 'factory_girl', :source => 'http://gems.github.com'
config.gem 'flexmock'

config.gem 'spicycode-rcov', :lib => 'rcov', :source => 'http://gems.github.com'
config.gem 'jgre-monkeyspecdoc', :lib => 'monkeyspecdoc', :source => 'http://gems.github.com'

# Only load the plugins named here, in the order given. By default, all plugins
# in vendor/plugins are loaded in alphabetical order.
# :all can be used as a placeholder for all plugins not explicitly named
@@ -0,0 +1,72 @@
# Hijacker class
#
# This class is used by RoleRequirementTestHelper to temporarily hijack a controller action for testing
#
# Example usage:
# hijacker = Hijacker.new(ListingsController)
# hijacker.hijack_instance_method("index", "render :text => 'hello world!'" )
# get :index # will return "hello world"
# hijacker.restore # put things back the way you found it

class Hijacker
def initialize(klass)
@target_klass = klass
@method_stores = {}
end

def hijack_class_method(method_name, eval_string = nil, arg_names = [], &block)
hijack_method(class_self_instance, method_name, eval_string, arg_names, &block )
end

def hijack_instance_method(method_name, eval_string = nil, arg_names = [], &block)
hijack_method(@target_klass, method_name, eval_string, arg_names, &block )
end

# restore all
def restore
@method_stores.each_pair{|klass, method_stores|
method_stores.reverse_each{ |method_name, method|
klass.send :undef_method, method_name
klass.send :define_method, method_name, method if method
}
}
@method_stores.clear
true
rescue
false
end

protected

def class_self_instance
@target_klass.send :eval, "class << self; self; end;"
end

def hijack_method(klass, method_name, eval_string = nil, arg_names = [], &block)
method_name = method_name.to_s
# You have got love ruby! What other language allows you to pillage and plunder a class like this?

(@method_stores[klass]||=[]) << [
method_name,
klass.instance_methods.include?(method_name) && klass.instance_method(method_name)
]

klass.send :undef_method, method_name
if Symbol === eval_string
klass.send :define_method, method_name, klass.instance_methods(eval_string)
elsif String === eval_string
klass.class_eval <<-EOF
def #{method_name}(#{arg_names * ','})
#{eval_string}
end
EOF
elsif block_given?
klass.send :define_method, method_name, block
end

true
rescue
false
end

end

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 5bd3c74

Please sign in to comment.