Permalink
Browse files

More syntaxic sugar

  • Loading branch information...
Joseph HALTER
Joseph HALTER committed Aug 13, 2009
1 parent b3933d5 commit 2da85113e85c8647462c0824d9d8e112cb0a5612
@@ -3,7 +3,7 @@
describe "have_column_matcher" do
before :all do
- define_model :Item
+ define_model :item
end
subject{ Item }
@@ -3,10 +3,10 @@
describe "have_many_to_many_matcher" do
before :all do
- define_model(:Item)
- define_model(:Comment){
+ define_model :item
+ define_model :comment do
many_to_many :items
- }
+ end
end
subject{ Comment }
@@ -3,10 +3,10 @@
describe "have_many_to_one_matcher" do
before :all do
- define_model(:Item)
- define_model(:Comment){
+ define_model :item
+ define_model :comment do
many_to_one :item
- }
+ end
end
subject{ Comment }
@@ -3,10 +3,10 @@
describe "have_one_to_many_matcher" do
before :all do
- define_model(:Item){
+ define_model :item do
one_to_many :comments
- }
- define_model(:Comment)
+ end
+ define_model :comment
end
subject{ Item }
View
@@ -13,15 +13,17 @@
end
def define_model(model, &block)
+ model_name = model.to_s.camelize.to_sym
+ table_name = model.to_s.tableize.to_sym
@defined_models ||= []
- @defined_models << model
- klass = Object.const_set model, Sequel::Model(model.to_s.tableize.to_sym)
+ @defined_models << model_name
+ klass = Object.const_set model_name, Sequel::Model(table_name)
klass.class_eval &block if block_given?
end
def undefine_models
- @defined_models.each{|model|
- Object.send(:remove_const, model)
+ @defined_models.each{|model_name|
+ Object.send(:remove_const, model_name)
}
@defined_models = []
end
@@ -3,12 +3,12 @@
describe "validate_exact_length_matcher" do
before :all do
- define_model(:Item){
+ define_model :item do
plugin :validation_helpers
def validate
validates_exact_length 4, :name, :allow_nil => true
end
- }
+ end
end
subject{ Item }
@@ -3,12 +3,12 @@
describe "validate_presence_matcher" do
before :all do
- define_model(:Item){
+ define_model :item do
plugin :validation_helpers
def validate
validates_presence [:id, :name], :allow_nil => true
end
- }
+ end
end
subject{ Item }

0 comments on commit 2da8511

Please sign in to comment.