transactionata 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.rdoc +62 -0
- data/Rakefile +33 -0
- data/lib/transactionata/version.rb +3 -0
- data/lib/transactionata.rb +38 -0
- data/test/helper.rb +9 -0
- data/test/rails2/Gemfile +14 -0
- data/test/rails2/Rakefile +10 -0
- data/test/rails2/app/controllers/application_controller.rb +3 -0
- data/test/rails2/app/controllers/posts_controller.rb +83 -0
- data/test/rails2/app/controllers/users_controller.rb +83 -0
- data/test/rails2/app/helpers/application_helper.rb +3 -0
- data/test/rails2/app/helpers/posts_helper.rb +2 -0
- data/test/rails2/app/helpers/users_helper.rb +2 -0
- data/test/rails2/app/models/post.rb +6 -0
- data/test/rails2/app/models/user.rb +9 -0
- data/test/rails2/app/views/layouts/application.html.erb +14 -0
- data/test/rails2/app/views/layouts/posts.html.erb +17 -0
- data/test/rails2/app/views/layouts/users.html.erb +17 -0
- data/test/rails2/app/views/posts/edit.html.erb +24 -0
- data/test/rails2/app/views/posts/index.html.erb +24 -0
- data/test/rails2/app/views/posts/new.html.erb +23 -0
- data/test/rails2/app/views/posts/show.html.erb +18 -0
- data/test/rails2/app/views/users/edit.html.erb +28 -0
- data/test/rails2/app/views/users/index.html.erb +26 -0
- data/test/rails2/app/views/users/new.html.erb +27 -0
- data/test/rails2/app/views/users/show.html.erb +23 -0
- data/test/rails2/config/boot.rb +128 -0
- data/test/rails2/config/database.yml +22 -0
- data/test/rails2/config/environment.rb +38 -0
- data/test/rails2/config/environments/development.rb +17 -0
- data/test/rails2/config/environments/production.rb +28 -0
- data/test/rails2/config/environments/test.rb +28 -0
- data/test/rails2/config/initializers/cookie_verification_secret.rb +7 -0
- data/test/rails2/config/initializers/new_rails_defaults.rb +21 -0
- data/test/rails2/config/initializers/session_store.rb +15 -0
- data/test/rails2/config/locales/en.yml +5 -0
- data/test/rails2/config/preinitializer.rb +20 -0
- data/test/rails2/config/routes.rb +49 -0
- data/test/rails2/db/migrate/20110214150055_create_posts.rb +15 -0
- data/test/rails2/db/migrate/20110214150128_create_users.rb +16 -0
- data/test/rails2/script/about +4 -0
- data/test/rails2/script/console +3 -0
- data/test/rails2/script/dbconsole +3 -0
- data/test/rails2/script/destroy +3 -0
- data/test/rails2/script/generate +3 -0
- data/test/rails2/script/performance/benchmarker +3 -0
- data/test/rails2/script/performance/profiler +3 -0
- data/test/rails2/script/plugin +3 -0
- data/test/rails2/script/runner +3 -0
- data/test/rails2/script/server +3 -0
- data/test/rails2/test/factories/posts_factory.rb +4 -0
- data/test/rails2/test/factories/users_factory.rb +7 -0
- data/test/rails2/test/fixtures/posts.yml +9 -0
- data/test/rails2/test/fixtures/users.yml +1 -0
- data/test/rails2/test/functional/posts_controller_test.rb +57 -0
- data/test/rails2/test/functional/users_controller_test.rb +57 -0
- data/test/rails2/test/integration/ui_test.rb +26 -0
- data/test/rails2/test/test_helper.rb +38 -0
- data/test/rails2/test/unit/helpers/posts_helper_test.rb +4 -0
- data/test/rails2/test/unit/helpers/users_helper_test.rb +4 -0
- data/test/rails2/test/unit/post_test.rb +42 -0
- data/test/rails2/test/unit/user_test.rb +32 -0
- data/test/rails3/Gemfile +37 -0
- data/test/rails3/Rakefile +7 -0
- data/test/rails3/app/controllers/application_controller.rb +3 -0
- data/test/rails3/app/controllers/posts_controller.rb +83 -0
- data/test/rails3/app/controllers/users_controller.rb +83 -0
- data/test/rails3/app/helpers/application_helper.rb +2 -0
- data/test/rails3/app/helpers/posts_helper.rb +2 -0
- data/test/rails3/app/helpers/users_helper.rb +2 -0
- data/test/rails3/app/models/post.rb +6 -0
- data/test/rails3/app/models/user.rb +9 -0
- data/test/rails3/app/views/layouts/application.html.erb +14 -0
- data/test/rails3/app/views/posts/_form.html.erb +25 -0
- data/test/rails3/app/views/posts/edit.html.erb +6 -0
- data/test/rails3/app/views/posts/index.html.erb +25 -0
- data/test/rails3/app/views/posts/new.html.erb +5 -0
- data/test/rails3/app/views/posts/show.html.erb +15 -0
- data/test/rails3/app/views/users/_form.html.erb +33 -0
- data/test/rails3/app/views/users/edit.html.erb +6 -0
- data/test/rails3/app/views/users/index.html.erb +29 -0
- data/test/rails3/app/views/users/new.html.erb +5 -0
- data/test/rails3/app/views/users/show.html.erb +25 -0
- data/test/rails3/config/application.rb +42 -0
- data/test/rails3/config/boot.rb +6 -0
- data/test/rails3/config/database.yml +22 -0
- data/test/rails3/config/environment.rb +5 -0
- data/test/rails3/config/environments/development.rb +26 -0
- data/test/rails3/config/environments/test.rb +35 -0
- data/test/rails3/config/initializers/secret_token.rb +7 -0
- data/test/rails3/config/initializers/session_store.rb +8 -0
- data/test/rails3/config/locales/en.yml +5 -0
- data/test/rails3/config/routes.rb +62 -0
- data/test/rails3/config.ru +4 -0
- data/test/rails3/db/.gitkeep +0 -0
- data/test/rails3/db/migrate/20110212112626_create_posts.rb +14 -0
- data/test/rails3/db/migrate/20110212120554_create_users.rb +16 -0
- data/test/rails3/db/migrate/20110213220543_add_user_reference_to_post.rb +9 -0
- data/test/rails3/script/rails +6 -0
- data/test/rails3/test/factories/posts_factory.rb +4 -0
- data/test/rails3/test/factories/users_factory.rb +7 -0
- data/test/rails3/test/fixtures/posts.yml +9 -0
- data/test/rails3/test/fixtures/users.yml +1 -0
- data/test/rails3/test/functional/posts_controller_test.rb +57 -0
- data/test/rails3/test/functional/users_controller_test.rb +57 -0
- data/test/rails3/test/integration/ui_test.rb +26 -0
- data/test/rails3/test/performance/browsing_test.rb +9 -0
- data/test/rails3/test/test_helper.rb +13 -0
- data/test/rails3/test/unit/helpers/posts_helper_test.rb +4 -0
- data/test/rails3/test/unit/helpers/users_helper_test.rb +4 -0
- data/test/rails3/test/unit/post_test.rb +42 -0
- data/test/rails3/test/unit/user_test.rb +32 -0
- data/test/test_rails2_integration.rb +26 -0
- data/test/test_rails3_integration.rb +26 -0
- data/transactionata.gemspec +24 -0
- metadata +316 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
3
|
+
require 'test_help'
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
# Transactional fixtures accelerate your tests by wrapping each test method
|
7
|
+
# in a transaction that's rolled back on completion. This ensures that the
|
8
|
+
# test database remains unchanged so your fixtures don't have to be reloaded
|
9
|
+
# between every test method. Fewer database queries means faster tests.
|
10
|
+
#
|
11
|
+
# Read Mike Clark's excellent walkthrough at
|
12
|
+
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
13
|
+
#
|
14
|
+
# Every Active Record database supports transactions except MyISAM tables
|
15
|
+
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
16
|
+
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
17
|
+
# is recommended.
|
18
|
+
#
|
19
|
+
# The only drawback to using transactional fixtures is when you actually
|
20
|
+
# need to test transactions. Since your test is bracketed by a transaction,
|
21
|
+
# any transactions started in your code will be automatically rolled back.
|
22
|
+
self.use_transactional_fixtures = true
|
23
|
+
|
24
|
+
# Instantiated fixtures are slow, but give you @david where otherwise you
|
25
|
+
# would need people(:david). If you don't want to migrate your existing
|
26
|
+
# test cases which use the @david style and don't mind the speed hit (each
|
27
|
+
# instantiated fixtures translates to a database query per test method),
|
28
|
+
# then set this back to true.
|
29
|
+
self.use_instantiated_fixtures = false
|
30
|
+
|
31
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
32
|
+
#
|
33
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
34
|
+
# -- they do not yet inherit this setting
|
35
|
+
fixtures :all
|
36
|
+
|
37
|
+
# Add more helper methods to be used by all tests here...
|
38
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PostTest < ActiveSupport::TestCase
|
4
|
+
test_data do
|
5
|
+
puts "Loading test data in #{self}"
|
6
|
+
10.times do
|
7
|
+
Factory.create(:post)
|
8
|
+
end
|
9
|
+
Factory.create(:post, :title => "Foobar")
|
10
|
+
end
|
11
|
+
|
12
|
+
should belong_to(:user)
|
13
|
+
|
14
|
+
# 11 from test data, 2 from fixtures
|
15
|
+
should "have 13 Posts existing" do
|
16
|
+
assert_equal 13, Post.count
|
17
|
+
end
|
18
|
+
|
19
|
+
should "delete 5 posts" do
|
20
|
+
5.times { assert Post.last.delete }
|
21
|
+
end
|
22
|
+
|
23
|
+
should "destroy 5 posts" do
|
24
|
+
5.times { assert Post.last.delete }
|
25
|
+
end
|
26
|
+
|
27
|
+
should "have post with title 'Foobar'" do
|
28
|
+
assert Post.find_by_title('Foobar')
|
29
|
+
end
|
30
|
+
|
31
|
+
should "have no post with title 'Whatever'" do
|
32
|
+
assert !Post.find_by_title('Whatever')
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
context "after destroying 3 posts" do
|
37
|
+
setup { 3.times { Post.last.destroy } }
|
38
|
+
should "have 10 Posts remaining" do
|
39
|
+
assert_equal 10, Post.count
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UserTest < ActiveSupport::TestCase
|
4
|
+
test_data do
|
5
|
+
puts "Loading test data in #{self}"
|
6
|
+
user = Factory.create(:user, :login => 'testuser')
|
7
|
+
|
8
|
+
5.times do
|
9
|
+
Factory.create(:post, :user => user)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
should have_many(:posts)
|
14
|
+
|
15
|
+
should "create properly from Factory" do
|
16
|
+
assert user = Factory.create(:user)
|
17
|
+
end
|
18
|
+
|
19
|
+
should "delete all" do
|
20
|
+
User.delete_all
|
21
|
+
assert_equal 0, User.count
|
22
|
+
end
|
23
|
+
|
24
|
+
should "have have only the posts that belong to user and 2 from fixtures" do
|
25
|
+
assert_equal 7, Post.count
|
26
|
+
assert_equal 5, User.find_by_login!('testuser').posts.count
|
27
|
+
end
|
28
|
+
|
29
|
+
should "have one User present" do
|
30
|
+
assert_equal 1, User.count
|
31
|
+
end
|
32
|
+
end
|
data/test/rails3/Gemfile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '3.0.4'
|
4
|
+
|
5
|
+
# Bundle edge Rails instead:
|
6
|
+
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
7
|
+
|
8
|
+
gem 'sqlite3'
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem 'shoulda'
|
12
|
+
gem 'factory_girl_rails'
|
13
|
+
gem 'transactionata', :path => '../../'
|
14
|
+
end
|
15
|
+
|
16
|
+
# Use unicorn as the web server
|
17
|
+
# gem 'unicorn'
|
18
|
+
|
19
|
+
# Deploy with Capistrano
|
20
|
+
# gem 'capistrano'
|
21
|
+
|
22
|
+
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
|
23
|
+
# gem 'ruby-debug'
|
24
|
+
# gem 'ruby-debug19'
|
25
|
+
|
26
|
+
# Bundle the extra gems:
|
27
|
+
# gem 'bj'
|
28
|
+
# gem 'nokogiri'
|
29
|
+
# gem 'sqlite3-ruby', :require => 'sqlite3'
|
30
|
+
# gem 'aws-s3', :require => 'aws/s3'
|
31
|
+
|
32
|
+
# Bundle gems for the local environment. Make sure to
|
33
|
+
# put test-only gems in this group so their generators
|
34
|
+
# and rake tasks are available in development mode:
|
35
|
+
# group :development, :test do
|
36
|
+
# gem 'webrat'
|
37
|
+
# end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
require 'rake'
|
6
|
+
|
7
|
+
Rails3::Application.load_tasks
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class PostsController < ApplicationController
|
2
|
+
# GET /posts
|
3
|
+
# GET /posts.xml
|
4
|
+
def index
|
5
|
+
@posts = Post.all
|
6
|
+
|
7
|
+
respond_to do |format|
|
8
|
+
format.html # index.html.erb
|
9
|
+
format.xml { render :xml => @posts }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /posts/1
|
14
|
+
# GET /posts/1.xml
|
15
|
+
def show
|
16
|
+
@post = Post.find(params[:id])
|
17
|
+
|
18
|
+
respond_to do |format|
|
19
|
+
format.html # show.html.erb
|
20
|
+
format.xml { render :xml => @post }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# GET /posts/new
|
25
|
+
# GET /posts/new.xml
|
26
|
+
def new
|
27
|
+
@post = Post.new
|
28
|
+
|
29
|
+
respond_to do |format|
|
30
|
+
format.html # new.html.erb
|
31
|
+
format.xml { render :xml => @post }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# GET /posts/1/edit
|
36
|
+
def edit
|
37
|
+
@post = Post.find(params[:id])
|
38
|
+
end
|
39
|
+
|
40
|
+
# POST /posts
|
41
|
+
# POST /posts.xml
|
42
|
+
def create
|
43
|
+
@post = Post.new(params[:post])
|
44
|
+
|
45
|
+
respond_to do |format|
|
46
|
+
if @post.save
|
47
|
+
format.html { redirect_to(@post, :notice => 'Post was successfully created.') }
|
48
|
+
format.xml { render :xml => @post, :status => :created, :location => @post }
|
49
|
+
else
|
50
|
+
format.html { render :action => "new" }
|
51
|
+
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# PUT /posts/1
|
57
|
+
# PUT /posts/1.xml
|
58
|
+
def update
|
59
|
+
@post = Post.find(params[:id])
|
60
|
+
|
61
|
+
respond_to do |format|
|
62
|
+
if @post.update_attributes(params[:post])
|
63
|
+
format.html { redirect_to(@post, :notice => 'Post was successfully updated.') }
|
64
|
+
format.xml { head :ok }
|
65
|
+
else
|
66
|
+
format.html { render :action => "edit" }
|
67
|
+
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# DELETE /posts/1
|
73
|
+
# DELETE /posts/1.xml
|
74
|
+
def destroy
|
75
|
+
@post = Post.find(params[:id])
|
76
|
+
@post.destroy
|
77
|
+
|
78
|
+
respond_to do |format|
|
79
|
+
format.html { redirect_to(posts_url) }
|
80
|
+
format.xml { head :ok }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class UsersController < ApplicationController
|
2
|
+
# GET /users
|
3
|
+
# GET /users.xml
|
4
|
+
def index
|
5
|
+
@users = User.all
|
6
|
+
|
7
|
+
respond_to do |format|
|
8
|
+
format.html # index.html.erb
|
9
|
+
format.xml { render :xml => @users }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /users/1
|
14
|
+
# GET /users/1.xml
|
15
|
+
def show
|
16
|
+
@user = User.find(params[:id])
|
17
|
+
|
18
|
+
respond_to do |format|
|
19
|
+
format.html # show.html.erb
|
20
|
+
format.xml { render :xml => @user }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# GET /users/new
|
25
|
+
# GET /users/new.xml
|
26
|
+
def new
|
27
|
+
@user = User.new
|
28
|
+
|
29
|
+
respond_to do |format|
|
30
|
+
format.html # new.html.erb
|
31
|
+
format.xml { render :xml => @user }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# GET /users/1/edit
|
36
|
+
def edit
|
37
|
+
@user = User.find(params[:id])
|
38
|
+
end
|
39
|
+
|
40
|
+
# POST /users
|
41
|
+
# POST /users.xml
|
42
|
+
def create
|
43
|
+
@user = User.new(params[:user])
|
44
|
+
|
45
|
+
respond_to do |format|
|
46
|
+
if @user.save
|
47
|
+
format.html { redirect_to(@user, :notice => 'User was successfully created.') }
|
48
|
+
format.xml { render :xml => @user, :status => :created, :location => @user }
|
49
|
+
else
|
50
|
+
format.html { render :action => "new" }
|
51
|
+
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# PUT /users/1
|
57
|
+
# PUT /users/1.xml
|
58
|
+
def update
|
59
|
+
@user = User.find(params[:id])
|
60
|
+
|
61
|
+
respond_to do |format|
|
62
|
+
if @user.update_attributes(params[:user])
|
63
|
+
format.html { redirect_to(@user, :notice => 'User was successfully updated.') }
|
64
|
+
format.xml { head :ok }
|
65
|
+
else
|
66
|
+
format.html { render :action => "edit" }
|
67
|
+
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# DELETE /users/1
|
73
|
+
# DELETE /users/1.xml
|
74
|
+
def destroy
|
75
|
+
@user = User.find(params[:id])
|
76
|
+
@user.destroy
|
77
|
+
|
78
|
+
respond_to do |format|
|
79
|
+
format.html { redirect_to(users_url) }
|
80
|
+
format.xml { head :ok }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
attr_accessor :password_confirmation
|
3
|
+
validate :name, :presence => true
|
4
|
+
validate :login, :presence => true, :uniqueness => true
|
5
|
+
validate :email, :presence => true, :uniqueness => true
|
6
|
+
validate :password, :presence => true, :confirmation => true
|
7
|
+
|
8
|
+
has_many :posts
|
9
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<%= form_for(@post) do |f| %>
|
2
|
+
<% if @post.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @post.errors.full_messages.each do |msg| %>
|
8
|
+
<li><%= msg %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
<%= f.label :title %><br />
|
16
|
+
<%= f.text_field :title %>
|
17
|
+
</div>
|
18
|
+
<div class="field">
|
19
|
+
<%= f.label :body %><br />
|
20
|
+
<%= f.text_area :body %>
|
21
|
+
</div>
|
22
|
+
<div class="actions">
|
23
|
+
<%= f.submit %>
|
24
|
+
</div>
|
25
|
+
<% end %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<h1>Listing posts</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th>Title</th>
|
6
|
+
<th>Body</th>
|
7
|
+
<th></th>
|
8
|
+
<th></th>
|
9
|
+
<th></th>
|
10
|
+
</tr>
|
11
|
+
|
12
|
+
<% @posts.each do |post| %>
|
13
|
+
<tr>
|
14
|
+
<td><%= post.title %></td>
|
15
|
+
<td><%= post.body %></td>
|
16
|
+
<td><%= link_to 'Show', post %></td>
|
17
|
+
<td><%= link_to 'Edit', edit_post_path(post) %></td>
|
18
|
+
<td><%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %></td>
|
19
|
+
</tr>
|
20
|
+
<% end %>
|
21
|
+
</table>
|
22
|
+
|
23
|
+
<br />
|
24
|
+
|
25
|
+
<%= link_to 'New Post', new_post_path %>
|