spec/integration/select_spec.rb in dm-is-select-0.0.7 vs spec/integration/select_spec.rb in dm-is-select-0.0.8
- old
+ new
@@ -2,57 +2,49 @@
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
describe 'DataMapper::Is::Select' do
- class Category
- include DataMapper::Resource
- property :id, Serial
- property :name, String
- property :publish_status, String, :default => "on"
+ before(:each) do
- is :select, :name
+ class Category
+ include DataMapper::Resource
+ property :id, Serial
+ property :name, String
+ property :publish_status, String, :default => "on"
+
+ is :select, :name
+ end
- auto_migrate!
- end
-
- class TreeCategory
- include DataMapper::Resource
- property :id, Serial
- property :name, String
- property :publish_status, String, :default => "on"
+ class TreeCategory
+ include DataMapper::Resource
+ property :id, Serial
+ property :name, String
+ property :publish_status, String, :default => "on"
+ # property :parent_id, Integer
+
+ is :tree, :order => :name
+ is :select, :name, :is_tree => true
+ end
- is :tree, :order => :name
- is :select, :name, :is_tree => true
+ class Country
+ include DataMapper::Resource
+ property :code, String, :key => true
+ property :name, String
+ is :select, :name, :value_field => :code
+ end #/ Country
- auto_migrate!
- end
-
-
- class Country
- include DataMapper::Resource
- property :code, String, :key => true
- property :name, String
- is :select, :name, :value_field => :code
+ DataMapper.finalize
- auto_migrate!
- end #/ Country
-
- 5.times do |n|
- Category.create(:name => "Category #{n+1}")
+ DataMapper.auto_migrate!
+
end
- 2.times do |parent_id|
- parent_id += 1
- parent = TreeCategory.create(:name => "TreeCategory-#{parent_id}" , :parent_id => 0 )
- child = TreeCategory.create(:name => "TreeCategory-#{parent_id}-Child" , :parent_id => parent.id )
- grandchild = TreeCategory.create(:name => "TreeCategory-#{parent_id}-Child-GrandChild" , :parent_id => child.id )
+ it "should use DM-Core 1.0.0.rc3" do
+ DataMapper::VERSION.should == '1.0.0.rc3'
end
- 3.times do |i|
- Country.create(:code => "A#{i}", :name => "Country#{i}")
- end
describe "Class Methods" do
describe "is :select" do
@@ -62,13 +54,14 @@
include DataMapper::Resource
property :id, Serial
property :name, String
is :select, 'name'
- auto_migrate!
end
+ DataMapper.auto_migrate!
+
}.should_not raise_error(ArgumentError)
end
it "should raise an ArgumentError if non-existant field is provided" do
lambda {
@@ -76,22 +69,28 @@
include DataMapper::Resource
property :id, Serial
property :name, String
is :select, :does_not_exist
- auto_migrate!
end
+ DataMapper.auto_migrate!
}.should raise_error(ArgumentError)
end
end #/ is :select
describe "#items_for_select_menu" do
describe "A Normal Model" do
+ before(:each) do
+ 5.times do |n|
+ Category.create(:name => "Category #{n+1}")
+ end
+ end
+
it "should return the default select options when given no params" do
Category.items_for_select_menu.should == [
[nil, "Select Category"],
["nil", " ------ "],
[1, "Category 1"],
@@ -173,10 +172,11 @@
[3, "Category 3"],
[2, "Category 2"],
# [1, "Category 1"]
]
end
+
it "should handle invalid SQL select options" do
Category.items_for_select_menu(:publish_status => "invalid", :order => [ :id.desc ] ).should == [
[nil, "Select Category"],
["nil", " ------ "],
# [5, "Category 5"],
@@ -189,10 +189,20 @@
end #/ Normal Model
describe "Tree Model" do
+ before(:each) do
+ 2.times do |parent_id|
+ parent_id += 1
+ theparent = TreeCategory.create(:name => "TreeCategory-#{parent_id}") # sets parent_id => nil
+ child = TreeCategory.create(:name => "TreeCategory-#{parent_id}-Child" , :parent => theparent )
+ grandchild = TreeCategory.create(:name => "TreeCategory-#{parent_id}-Child-GrandChild" , :parent_id => child.id )
+ end
+
+ end
+
it "should return the default select options when given no params" do
TreeCategory.items_for_select_menu.should == [
[nil, "Select TreeCategory"],
["nil", " ------ "],
[0, "Top Level TreeCategory"],
@@ -284,9 +294,15 @@
end
end #/ Tree Model
describe "A value_field model" do
+
+ before(:each) do
+ 3.times do |i|
+ Country.create(:code => "A#{i}", :name => "Country#{i}")
+ end
+ end
it "should return the default select options when given no params" do
Country.items_for_select_menu.should == [
[nil, "Select Country"],
["nil", " ------ "],