Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add tests for models with composite primary keys

  • Loading branch information...
commit a3789105645167409e562d0b083bdd6e2f8dde6d 1 parent 38c2353
Petteri Kääpä authored January 20, 2011
2  spec/dummy_app/config/initializers/rails_admin.rb
... ...
@@ -1,3 +1,3 @@
1 1
 RailsAdmin.config do |c|
2  
-  c.excluded_models << RelTest
  2
+  c.excluded_models << RelTest << CompositePrimaryKeyTest
3 3
 end
50  spec/requests/composite_primary_key_test.rb
... ...
@@ -0,0 +1,50 @@
  1
+require 'spec_helper'
  2
+
  3
+describe 'a model with natural composite primary keys' do
  4
+
  5
+  before(:all) do
  6
+    RailsAdmin::Config.excluded_models = []
  7
+  end
  8
+
  9
+  after(:all) do
  10
+    RailsAdmin::Config.excluded_models = [RelTest, CompositePrimaryKeyTest]
  11
+    RailsAdmin::AbstractModel.instance_variable_get("@models").clear
  12
+    RailsAdmin::Config.reset
  13
+  end
  14
+
  15
+  before(:each) do
  16
+    @abstract_model = RailsAdmin::AbstractModel.new(CompositePrimaryKeyTest)
  17
+    @object = @abstract_model.create(:pk1 => 1, :pk2 => "test", :pk3 => "2011-01-01")
  18
+  end
  19
+
  20
+  it 'should report correct primary keys' do
  21
+    @abstract_model.primary_keys.should == ["pk1", "pk2", "pk3"]
  22
+  end
  23
+
  24
+  it 'should report primary key value correctly' do
  25
+    @abstract_model.get_id(@object).should == [1, "test", Date.parse("2011-01-01")]
  26
+  end
  27
+
  28
+  it 'should have a create page with primary key fields visible' do
  29
+    get rails_admin_new_path(:model_name => @abstract_model.to_param)
  30
+
  31
+    response.should have_tag(".field") do |elements|
  32
+      elements.should have_tag("#composite_primary_key_tests_pk1")
  33
+      elements.should have_tag("#composite_primary_key_tests_pk2")
  34
+      elements.should have_tag("#composite_primary_key_tests_pk3")
  35
+      elements.should have_tag("#composite_primary_key_tests_description")
  36
+    end
  37
+  end
  38
+
  39
+  it 'should have an update page with primary key fields hidden' do
  40
+
  41
+    get rails_admin_edit_path(:model_name => @abstract_model.to_param, :id => @abstract_model.get_id(@object))
  42
+
  43
+    response.should have_tag(".field") do |elements|
  44
+      elements.should_not have_tag("#composite_primary_key_tests_pk1")
  45
+      elements.should_not have_tag("#composite_primary_key_tests_pk2")
  46
+      elements.should_not have_tag("#composite_primary_key_tests_pk3")
  47
+      elements.should have_tag("#composite_primary_key_tests_description")
  48
+    end
  49
+  end
  50
+end
10  spec/requests/config/rails_admin_config_spec.rb
@@ -10,7 +10,7 @@
10 10
     end
11 11
 
12 12
     after(:all) do
13  
-      RailsAdmin::Config.excluded_models = []
  13
+      RailsAdmin::Config.excluded_models = [RelTest, CompositePrimaryKeyTest]
14 14
       RailsAdmin::AbstractModel.instance_variable_get("@models").clear
15 15
       RailsAdmin::Config.reset
16 16
     end
@@ -53,11 +53,11 @@
53 53
       end
54 54
     end
55 55
   end
56  
-  
  56
+
57 57
   describe "model store does not exist" do
58 58
     before(:each)  { drop_all_tables }
59 59
     after(:all)    { migrate_database }
60  
-    
  60
+
61 61
     it "should not raise an error when the model tables do not exists" do
62 62
       config_setup = lambda do
63 63
         RailsAdmin.config Team do
@@ -66,9 +66,9 @@
66 66
           end
67 67
         end
68 68
       end
69  
-      
  69
+
70 70
       config_setup.should_not raise_error
71 71
     end
72 72
   end
73  
-  
  73
+
74 74
 end
1  spec/spec_helper.rb
@@ -58,6 +58,7 @@
58 58
     RailsAdmin::AbstractModel.new("Player").destroy_all!
59 59
     RailsAdmin::AbstractModel.new("Team").destroy_all!
60 60
     RailsAdmin::AbstractModel.new("User").destroy_all!
  61
+    RailsAdmin::AbstractModel.new("CompositePrimaryKeyTest").destroy_all!
61 62
 
62 63
     user = RailsAdmin::AbstractModel.new("User").create(
63 64
       :email => "test@test.com",

0 notes on commit a378910

Please sign in to comment.
Something went wrong with that request. Please try again.