Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add tests for models with composite primary keys

  • Loading branch information...
commit a3789105645167409e562d0b083bdd6e2f8dde6d 1 parent 38c2353
@kaapa kaapa authored
View
2  spec/dummy_app/config/initializers/rails_admin.rb
@@ -1,3 +1,3 @@
RailsAdmin.config do |c|
- c.excluded_models << RelTest
+ c.excluded_models << RelTest << CompositePrimaryKeyTest
end
View
50 spec/requests/composite_primary_key_test.rb
@@ -0,0 +1,50 @@
+require 'spec_helper'
+
+describe 'a model with natural composite primary keys' do
+
+ before(:all) do
+ RailsAdmin::Config.excluded_models = []
+ end
+
+ after(:all) do
+ RailsAdmin::Config.excluded_models = [RelTest, CompositePrimaryKeyTest]
+ RailsAdmin::AbstractModel.instance_variable_get("@models").clear
+ RailsAdmin::Config.reset
+ end
+
+ before(:each) do
+ @abstract_model = RailsAdmin::AbstractModel.new(CompositePrimaryKeyTest)
+ @object = @abstract_model.create(:pk1 => 1, :pk2 => "test", :pk3 => "2011-01-01")
+ end
+
+ it 'should report correct primary keys' do
+ @abstract_model.primary_keys.should == ["pk1", "pk2", "pk3"]
+ end
+
+ it 'should report primary key value correctly' do
+ @abstract_model.get_id(@object).should == [1, "test", Date.parse("2011-01-01")]
+ end
+
+ it 'should have a create page with primary key fields visible' do
+ get rails_admin_new_path(:model_name => @abstract_model.to_param)
+
+ response.should have_tag(".field") do |elements|
+ elements.should have_tag("#composite_primary_key_tests_pk1")
+ elements.should have_tag("#composite_primary_key_tests_pk2")
+ elements.should have_tag("#composite_primary_key_tests_pk3")
+ elements.should have_tag("#composite_primary_key_tests_description")
+ end
+ end
+
+ it 'should have an update page with primary key fields hidden' do
+
+ get rails_admin_edit_path(:model_name => @abstract_model.to_param, :id => @abstract_model.get_id(@object))
+
+ response.should have_tag(".field") do |elements|
+ elements.should_not have_tag("#composite_primary_key_tests_pk1")
+ elements.should_not have_tag("#composite_primary_key_tests_pk2")
+ elements.should_not have_tag("#composite_primary_key_tests_pk3")
+ elements.should have_tag("#composite_primary_key_tests_description")
+ end
+ end
+end
View
10 spec/requests/config/rails_admin_config_spec.rb
@@ -10,7 +10,7 @@
end
after(:all) do
- RailsAdmin::Config.excluded_models = []
+ RailsAdmin::Config.excluded_models = [RelTest, CompositePrimaryKeyTest]
RailsAdmin::AbstractModel.instance_variable_get("@models").clear
RailsAdmin::Config.reset
end
@@ -53,11 +53,11 @@
end
end
end
-
+
describe "model store does not exist" do
before(:each) { drop_all_tables }
after(:all) { migrate_database }
-
+
it "should not raise an error when the model tables do not exists" do
config_setup = lambda do
RailsAdmin.config Team do
@@ -66,9 +66,9 @@
end
end
end
-
+
config_setup.should_not raise_error
end
end
-
+
end
View
1  spec/spec_helper.rb
@@ -58,6 +58,7 @@
RailsAdmin::AbstractModel.new("Player").destroy_all!
RailsAdmin::AbstractModel.new("Team").destroy_all!
RailsAdmin::AbstractModel.new("User").destroy_all!
+ RailsAdmin::AbstractModel.new("CompositePrimaryKeyTest").destroy_all!
user = RailsAdmin::AbstractModel.new("User").create(
:email => "test@test.com",
Please sign in to comment.
Something went wrong with that request. Please try again.