Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
added shoulda tests, basic test for comments, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Adams committed Apr 20, 2009
1 parent c415593 commit 5bd3c74
Show file tree
Hide file tree
Showing 22 changed files with 627 additions and 1,230 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/page_plugins_controller.rb
Expand Up @@ -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
17 changes: 5 additions & 12 deletions app/models/comment.rb
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion config/environment.rb
Expand Up @@ -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
Expand Down
72 changes: 72 additions & 0 deletions lib/hijacker.rb
@@ -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
101 changes: 0 additions & 101 deletions spec/ansuz_installer_spec.rb

This file was deleted.

106 changes: 0 additions & 106 deletions spec/fixtures/pages.yml

This file was deleted.

22 changes: 0 additions & 22 deletions spec/fixtures/site_settings.yml

This file was deleted.

0 comments on commit 5bd3c74

Please sign in to comment.