imedo-dry_plugin_test_helper 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +72 -0
- data/fixtures/articles.yml +10 -0
- data/lib/dry_plugin_test_helper.rb +41 -0
- data/lib/plugin_test_environment.rb +38 -0
- data/lib/silent_logger.rb +11 -0
- data/rails_root/app/controllers/application.rb +2 -0
- data/rails_root/app/models/article.rb +6 -0
- data/rails_root/app/models/author.rb +5 -0
- data/rails_root/app/models/comment.rb +6 -0
- data/rails_root/app/models/user.rb +5 -0
- data/rails_root/config/boot.rb +45 -0
- data/rails_root/config/database.yml +18 -0
- data/rails_root/config/environment.rb +41 -0
- data/rails_root/config/environments/mysql.rb +0 -0
- data/rails_root/config/environments/postgresql.rb +0 -0
- data/rails_root/config/environments/sqlite.rb +0 -0
- data/rails_root/config/environments/sqlite3.rb +0 -0
- data/rails_root/config/routes.rb +9 -0
- data/rails_root/db/migrate/001_create_environment.rb +33 -0
- data/rails_root/script/console +3 -0
- data/rails_root/vendor/plugins/plugin_to_test/init.rb +3 -0
- metadata +92 -0
data/README.rdoc
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
= dry_plugin_test
|
2
|
+
|
3
|
+
Author:: Hendrik Volkmer - hvolkmer (at) imedo.de
|
4
|
+
Copyright:: Copyright (c) 2008 imedo GmbH
|
5
|
+
Licence:: MIT
|
6
|
+
Git:: http://github.com/imedo/dry_plugin_test_helper
|
7
|
+
Bugs:: No dedicated bug tracker yet - Email us or just send pull requests
|
8
|
+
|
9
|
+
Makes your plugin tests dry and isolates plugin tests from you real app.
|
10
|
+
|
11
|
+
== Dependencies
|
12
|
+
* Rails 2.0.2 (should work also with 1.2)
|
13
|
+
* sqlite3 - http://www.sqlite.org/
|
14
|
+
|
15
|
+
== Installation
|
16
|
+
|
17
|
+
The easiest way to install this gem is directly via the github gem
|
18
|
+
repository:
|
19
|
+
|
20
|
+
$ sudo gem install imedo-dry_plugin_test_helper -s http://gems.github.com
|
21
|
+
|
22
|
+
Or
|
23
|
+
|
24
|
+
download the source code and build the gem yourself
|
25
|
+
|
26
|
+
$ git clone git://github.com/imedo/dry_plugin_test_helper.git
|
27
|
+
$ cd dry_plugin_test_helper
|
28
|
+
$ rake
|
29
|
+
$ sudo gem install pkg/dry_plugin_test_helper-0.0.3.gem
|
30
|
+
|
31
|
+
== Usage
|
32
|
+
|
33
|
+
In your plugin test helper use these lines:
|
34
|
+
|
35
|
+
require 'rubygems'
|
36
|
+
require 'dry_plugin_test_helper'
|
37
|
+
|
38
|
+
PluginTestEnvironment.init_env(File.dirname(__FILE__))
|
39
|
+
|
40
|
+
|
41
|
+
This sets up the test environment which means you have a stub rails app with
|
42
|
+
you plugin loaded and also the following models:
|
43
|
+
|
44
|
+
* Article: belongs_to :author, has_many :comments
|
45
|
+
* Author: has_many :articles
|
46
|
+
* Comment: belongs_to :articles, belongs_to :user
|
47
|
+
* User: has_many :comments
|
48
|
+
|
49
|
+
The models will be added to a sqlite in memory database for fast testing.
|
50
|
+
|
51
|
+
You can add your own models using a migration in your test directory like
|
52
|
+
this:
|
53
|
+
|
54
|
+
PluginTestEnvironment::Migration.setup do
|
55
|
+
|
56
|
+
create_table "animals", :force => true do |t|
|
57
|
+
t.column "name", :string
|
58
|
+
t.column "age", :integer
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
If you don't want the standard models you can initialize the test environment
|
64
|
+
like this:
|
65
|
+
|
66
|
+
PluginTestEnvironment.init_env(File.dirname(__FILE__), false)
|
67
|
+
|
68
|
+
== TODO
|
69
|
+
* Tests for the test gem itself
|
70
|
+
* support for RSpec and other testing frameworks (might already work - haven't tried it)
|
71
|
+
* Automatic Rails version discovery
|
72
|
+
* Clean up / strip down rails env to bare minimum
|
@@ -0,0 +1,10 @@
|
|
1
|
+
first:
|
2
|
+
id: 1
|
3
|
+
title: "What's in the package?"
|
4
|
+
body: "Rails is a full-stack framework for developing database-backed web applications according to the Model-View-Control pattern. From the Ajax in the view, to the request and response in the controller, to the domain model wrapping the database, Rails gives you a pure-Ruby development environment. To go live, all you need to add is a database and a web server."
|
5
|
+
author_id: 1
|
6
|
+
second:
|
7
|
+
id: 2
|
8
|
+
title: "Who is already on Rails?"
|
9
|
+
body: "Everyone from startups to non-profits to enterprise organizations are using Rails. Rails is all about infrastructure so it's a great fit for practically any type of web application. Be it software for collaboration, community, e-commerce, content management, statistics, management, you name it."
|
10
|
+
author_id: 2
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_record'
|
4
|
+
|
5
|
+
ENV['RAILS_ENV'] ||= 'sqlite3'
|
6
|
+
|
7
|
+
require File.dirname(__FILE__) + '/silent_logger'
|
8
|
+
require File.dirname(__FILE__) + '/plugin_test_environment'
|
9
|
+
|
10
|
+
require 'time'
|
11
|
+
|
12
|
+
|
13
|
+
# Code by Jay Fields
|
14
|
+
# http://blog.jayfields.com/2007/11/ruby-timeis.html
|
15
|
+
class Time
|
16
|
+
def self.metaclass
|
17
|
+
class << self; self; end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.is(point_in_time)
|
21
|
+
new_time = case point_in_time
|
22
|
+
when String then Time.parse(point_in_time)
|
23
|
+
when Time then point_in_time
|
24
|
+
else raise ArgumentError.new("argument should be a string or time instance")
|
25
|
+
end
|
26
|
+
class << self
|
27
|
+
alias old_now now
|
28
|
+
end
|
29
|
+
metaclass.class_eval do
|
30
|
+
define_method :now do
|
31
|
+
new_time
|
32
|
+
end
|
33
|
+
end
|
34
|
+
yield
|
35
|
+
class << self
|
36
|
+
alias now old_now
|
37
|
+
undef old_now
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class PluginTestEnvironment
|
2
|
+
|
3
|
+
cattr_accessor :plugin_path
|
4
|
+
|
5
|
+
def self.init_env(dir, standard_migration = true)
|
6
|
+
self.plugin_path = "#{dir}/.."
|
7
|
+
require File.dirname(__FILE__) + '/../rails_root/config/environment.rb'
|
8
|
+
ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate") if standard_migration
|
9
|
+
plugin_migration
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.fixture_path
|
13
|
+
if File.exists?(PluginTestEnvironment.plugin_path + '/test/fixtures')
|
14
|
+
PluginTestEnvironment.plugin_path + '/test/fixtures'
|
15
|
+
else
|
16
|
+
File.dirname(__FILE__) + "/../fixtures/"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.log_path
|
21
|
+
PluginTestEnvironment.plugin_path + '/test/log'
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.plugin_migration
|
25
|
+
begin
|
26
|
+
require "#{PluginTestEnvironment.plugin_path}/test/migration"
|
27
|
+
Migration.up
|
28
|
+
rescue LoadError
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Migration < ActiveRecord::Migration
|
33
|
+
def self.setup(&block)
|
34
|
+
self.class.send(:define_method, :up, &block)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb
|
2
|
+
|
3
|
+
unless defined?(RAILS_ROOT)
|
4
|
+
root_path = File.join(File.dirname(__FILE__), '..')
|
5
|
+
|
6
|
+
unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
|
7
|
+
require 'pathname'
|
8
|
+
root_path = Pathname.new(root_path).cleanpath(true).to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
RAILS_ROOT = root_path
|
12
|
+
end
|
13
|
+
|
14
|
+
unless defined?(Rails::Initializer)
|
15
|
+
if File.directory?("#{RAILS_ROOT}/vendor/rails")
|
16
|
+
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
|
17
|
+
else
|
18
|
+
require 'rubygems'
|
19
|
+
|
20
|
+
environment_without_comments = IO.readlines(File.dirname(__FILE__) + '/environment.rb').reject { |l| l =~ /^#/ }.join
|
21
|
+
environment_without_comments =~ /[^#]RAILS_GEM_VERSION = '([\d.]+)'/
|
22
|
+
rails_gem_version = $1
|
23
|
+
|
24
|
+
if version = defined?(RAILS_GEM_VERSION) ? RAILS_GEM_VERSION : rails_gem_version
|
25
|
+
# Asking for 1.1.6 will give you 1.1.6.5206, if available -- makes it easier to use beta gems
|
26
|
+
rails_gem = Gem.cache.search('rails', "~>#{version}.0").sort_by { |g| g.version.version }.last
|
27
|
+
|
28
|
+
if rails_gem
|
29
|
+
gem "rails", "=#{rails_gem.version.version}"
|
30
|
+
require rails_gem.full_gem_path + '/lib/initializer'
|
31
|
+
else
|
32
|
+
STDERR.puts %(Cannot find gem for Rails ~>#{version}.0:
|
33
|
+
Install the missing gem with 'gem install -v=#{version} rails', or
|
34
|
+
change environment.rb to define RAILS_GEM_VERSION with your desired version.
|
35
|
+
)
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
else
|
39
|
+
gem "rails"
|
40
|
+
require 'initializer'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
Rails::Initializer.run(:set_load_path)
|
45
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
sqlite:
|
2
|
+
:adapter: sqlite
|
3
|
+
:dbfile: ':memory:'
|
4
|
+
sqlite3:
|
5
|
+
:adapter: sqlite3
|
6
|
+
:dbfile: ':memory:'
|
7
|
+
postgresql:
|
8
|
+
:adapter: postgresql
|
9
|
+
:username: postgres
|
10
|
+
:password: postgres
|
11
|
+
:database: most_popular_test
|
12
|
+
:min_messages: ERROR
|
13
|
+
mysql:
|
14
|
+
:adapter: mysql
|
15
|
+
:host: localhost
|
16
|
+
:username: root
|
17
|
+
:password:
|
18
|
+
:database: most_popular_test
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Specifies gem version of Rails to use when vendor/rails is not present
|
2
|
+
#RAILS_GEM_VERSION = '1.1.6'
|
3
|
+
RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
|
4
|
+
|
5
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
6
|
+
#require 'plugin_dependencies'
|
7
|
+
|
8
|
+
Rails::Initializer.run do |config|
|
9
|
+
config.logger = SilentLogger.new
|
10
|
+
config.log_level = :debug
|
11
|
+
|
12
|
+
config.cache_classes = false
|
13
|
+
config.whiny_nils = true
|
14
|
+
#config.breakpoint_server = true
|
15
|
+
config.load_paths << "#{File.dirname(__FILE__)}/../../../lib/"
|
16
|
+
end
|
17
|
+
|
18
|
+
Dependencies.log_activity = false
|
19
|
+
|
20
|
+
require 'test_help'
|
21
|
+
|
22
|
+
|
23
|
+
Test::Unit::TestCase.fixture_path = PluginTestEnvironment.fixture_path
|
24
|
+
$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
|
25
|
+
|
26
|
+
class Test::Unit::TestCase #:nodoc:
|
27
|
+
def create_fixtures(*table_names)
|
28
|
+
if block_given?
|
29
|
+
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
|
30
|
+
else
|
31
|
+
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
self.use_transactional_fixtures = false
|
36
|
+
self.use_instantiated_fixtures = false
|
37
|
+
end
|
38
|
+
|
39
|
+
# Load the testing framework
|
40
|
+
silence_warnings { RAILS_ENV = ENV['RAILS_ENV'] }
|
41
|
+
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,9 @@
|
|
1
|
+
ActionController::Routing::Routes.draw do |map|
|
2
|
+
# Allow downloading Web Service WSDL as a file with an extension
|
3
|
+
# instead of a file named 'wsdl'
|
4
|
+
map.connect ':controller/service.wsdl', :action => 'wsdl'
|
5
|
+
|
6
|
+
# Default route
|
7
|
+
map.connect ':controller/:action/:id.:format'
|
8
|
+
map.connect ':controller/:action/:id'
|
9
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class CreateEnvironment < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :articles do |t|
|
4
|
+
t.column :title, :string
|
5
|
+
t.column :body, :text
|
6
|
+
t.column :author_id, :integer
|
7
|
+
t.column :active, :integer, :default => 1
|
8
|
+
t.column :hidden, :integer, :default => 0
|
9
|
+
t.column :deactivated_at, :datetime
|
10
|
+
end
|
11
|
+
|
12
|
+
create_table :authors do |t|
|
13
|
+
t.column :name, :string
|
14
|
+
end
|
15
|
+
|
16
|
+
create_table :comments do |t|
|
17
|
+
t.column :body, :text
|
18
|
+
t.column :article_id, :integer
|
19
|
+
t.column :user_id, :integer
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table :users do |t|
|
23
|
+
t.column :name, :string
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.down
|
28
|
+
drop_table :articles
|
29
|
+
drop_table :authors
|
30
|
+
drop_table :comments
|
31
|
+
drop_table :users
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: imedo-dry_plugin_test_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hendrik Volkmer
|
8
|
+
autorequire: active_record
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-18 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activerecord
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.15.3
|
23
|
+
version:
|
24
|
+
description:
|
25
|
+
email: hvolkmer@imedo.de
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README.rdoc
|
32
|
+
files:
|
33
|
+
- lib/silent_logger.rb
|
34
|
+
- lib/dry_plugin_test_helper.rb
|
35
|
+
- lib/plugin_test_environment.rb
|
36
|
+
- rails_root/db
|
37
|
+
- rails_root/db/migrate
|
38
|
+
- rails_root/db/migrate/001_create_environment.rb
|
39
|
+
- rails_root/app
|
40
|
+
- rails_root/app/controllers
|
41
|
+
- rails_root/app/controllers/application.rb
|
42
|
+
- rails_root/app/models
|
43
|
+
- rails_root/app/models/author.rb
|
44
|
+
- rails_root/app/models/user.rb
|
45
|
+
- rails_root/app/models/article.rb
|
46
|
+
- rails_root/app/models/comment.rb
|
47
|
+
- rails_root/config
|
48
|
+
- rails_root/config/routes.rb
|
49
|
+
- rails_root/config/environments
|
50
|
+
- rails_root/config/environments/sqlite3.rb
|
51
|
+
- rails_root/config/environments/sqlite.rb
|
52
|
+
- rails_root/config/environments/postgresql.rb
|
53
|
+
- rails_root/config/environments/mysql.rb
|
54
|
+
- rails_root/config/database.yml
|
55
|
+
- rails_root/config/environment.rb
|
56
|
+
- rails_root/config/boot.rb
|
57
|
+
- rails_root/script
|
58
|
+
- rails_root/script/console
|
59
|
+
- rails_root/vendor
|
60
|
+
- rails_root/vendor/plugins
|
61
|
+
- rails_root/vendor/plugins/plugin_to_test
|
62
|
+
- rails_root/vendor/plugins/plugin_to_test/init.rb
|
63
|
+
- fixtures/articles.yml
|
64
|
+
- README.rdoc
|
65
|
+
has_rdoc: true
|
66
|
+
homepage: http://opensource.imedo.de/
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.0.1
|
88
|
+
signing_key:
|
89
|
+
specification_version: 2
|
90
|
+
summary: Providing dry standard test environment for Ruby on Rails plugins
|
91
|
+
test_files: []
|
92
|
+
|