Skip to content

Commit

Permalink
Naming convention for test specific classes under test
Browse files Browse the repository at this point in the history
  • Loading branch information
geekq committed Jan 28, 2013
1 parent c855840 commit 7b6c83b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ end

require 'rake'
Rake::TestTask.new do |t|
t.libs << 'test'
t.verbose = true
t.warning = true
t.test_files = FileList['test/*_test.rb'] + FileList['test/new_versions/*_test.rb']
end

Rake::TestTask.new do |t|
t.name = 'test_without_new_versions'
t.libs << 'test'
t.verbose = true
t.warning = true
t.pattern = 'test/*_test.rb'
Expand Down
30 changes: 15 additions & 15 deletions test/attr_protected_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.join(File.dirname(__FILE__), 'test_helper')
require 'test_helper'

$VERBOSE = false
require 'active_record'
Expand All @@ -10,7 +10,7 @@

ActiveRecord::Migration.verbose = false

class ProtectedOrder < ActiveRecord::Base
class AttrProtectedTestOrder < ActiveRecord::Base
include Workflow

workflow do
Expand All @@ -28,37 +28,37 @@ class ProtectedOrder < ActiveRecord::Base

end

ProtectedOrder.logger = Logger.new(STDOUT) # active_record 2.3 expects a logger instance
ProtectedOrder.logger.level = Logger::WARN # switch to Logger::DEBUG to see the SQL statements
AttrProtectedTestOrder.logger = Logger.new(STDOUT) # active_record 2.3 expects a logger instance
AttrProtectedTestOrder.logger.level = Logger::WARN # switch to Logger::DEBUG to see the SQL statements

class AttrProtectedTest < ActiveRecordTestCase

def setup
super

ActiveRecord::Schema.define do
create_table :protected_orders do |t|
create_table :attr_protected_test_orders do |t|
t.string :title, :null => false
t.string :workflow_state
end
end

exec "INSERT INTO protected_orders(title, workflow_state) VALUES('order1', 'submitted')"
exec "INSERT INTO protected_orders(title, workflow_state) VALUES('order2', 'accepted')"
exec "INSERT INTO protected_orders(title, workflow_state) VALUES('order3', 'accepted')"
exec "INSERT INTO protected_orders(title, workflow_state) VALUES('order4', 'accepted')"
exec "INSERT INTO protected_orders(title, workflow_state) VALUES('order5', 'accepted')"
exec "INSERT INTO protected_orders(title, workflow_state) VALUES('protected order', 'submitted')"
exec "INSERT INTO attr_protected_test_orders(title, workflow_state) VALUES('order1', 'submitted')"
exec "INSERT INTO attr_protected_test_orders(title, workflow_state) VALUES('order2', 'accepted')"
exec "INSERT INTO attr_protected_test_orders(title, workflow_state) VALUES('order3', 'accepted')"
exec "INSERT INTO attr_protected_test_orders(title, workflow_state) VALUES('order4', 'accepted')"
exec "INSERT INTO attr_protected_test_orders(title, workflow_state) VALUES('order5', 'accepted')"
exec "INSERT INTO attr_protected_test_orders(title, workflow_state) VALUES('protected order', 'submitted')"
end

def assert_state(title, expected_state, klass = ProtectedOrder)
def assert_state(title, expected_state, klass = AttrProtectedTestOrder)
o = klass.find_by_title(title)
assert_equal expected_state, o.read_attribute(klass.workflow_column)
o
end

test 'cannot mass-assign workflow_state if attr_protected' do
o = ProtectedOrder.find_by_title('order1')
o = AttrProtectedTestOrder.find_by_title('order1')
assert_equal 'submitted', o.read_attribute(:workflow_state)
o.update_attributes :workflow_state => 'some_bad_value'
assert_equal 'submitted', o.read_attribute(:workflow_state)
Expand Down Expand Up @@ -89,9 +89,9 @@ def assert_state(title, expected_state, klass = ProtectedOrder)
end

test 'access workflow specification' do
assert_equal 3, Order.workflow_spec.states.length
assert_equal 3, AttrProtectedTestOrder.workflow_spec.states.length
assert_equal ['submitted', 'accepted', 'shipped'].sort,
Order.workflow_spec.state_names.map{|n| n.to_s}.sort
AttrProtectedTestOrder.workflow_spec.state_names.map{|n| n.to_s}.sort
end

test 'current state object' do
Expand Down

0 comments on commit 7b6c83b

Please sign in to comment.