Class: ConstraintsTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/six-updater-web/vendor/plugins/active_scaffold/test/misc/constraints_test.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



97
98
99
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/misc/constraints_test.rb', line 97

def setup
  @test_object = ConstraintsTestObject.new
end

#test_constraint_conditions_for_configured_associationsObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/misc/constraints_test.rb', line 131

def test_constraint_conditions_for_configured_associations
  @test_object.active_scaffold_config = config_for('other_user')
  # has_one (vs belongs_to)
  assert_constraint_condition({:other_subscription => 5}, ['subscriptions.id = ?', 5], 'find the user with subscription #5')
  # habtm (vs habtm)
  assert_constraint_condition({:other_roles => 4}, ['roles_users.role_id = ?', 4], 'find all users with role #4')
  # has_one (vs polymorphic)
  assert_constraint_condition({:other_address => 11}, ['addresses.id = ?', 11], 'find the user with address #11')
  # reverse of a has_many :through
  assert_constraint_condition({:other_subscription => {:other_service => 5}}, ['services.id = ?', 5], 'find all users subscribed to service #5')

  @test_object.active_scaffold_config = config_for('other_subscription')
  # belongs_to (vs has_one)
  assert_constraint_condition({:other_user => 2}, ['subscriptions.user_id = ?', 2], 'find the subscription for user #2')
  # belongs_to (vs has_many)
  assert_constraint_condition({:other_service => 1}, ['subscriptions.service_id = ?', 1], 'find all subscriptions for service #1')

  @test_object.active_scaffold_config = config_for('other_service')
  # has_many (vs belongs_to)
  assert_constraint_condition({:other_subscriptions => 10}, ['subscriptions.id = ?', 10], 'find the service with subscription #10')
  # has_many :through (through has_many)
  assert_constraint_condition({:other_users => 7}, ['users.id = ?', 7], 'find the service with user #7')

  @test_object.active_scaffold_config = config_for('other_address')
  # belongs_to :polymorphic => true
  @test_object.params[:parent_model] = 'OtherUser'
  assert_constraint_condition({:other_addressable => 14}, ['addresses.other_addressable_id = ?', 14, 'addresses.other_addressable_type = ?', 'OtherUser'], 'find all addresses for user #14')
end

#test_constraint_conditions_for_default_associationsObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/misc/constraints_test.rb', line 101

def test_constraint_conditions_for_default_associations
  @test_object.active_scaffold_config = config_for('user')
  # has_one (vs belongs_to)
  assert_constraint_condition({:subscription => 5}, ['subscriptions.id = ?', 5], 'find the user with subscription #5')
  # habtm (vs habtm)
  assert_constraint_condition({:roles => 4}, ['roles_users.role_id = ?', 4], 'find all users with role #4')
  # has_one (vs polymorphic)
  assert_constraint_condition({:address => 11}, ['addresses.id = ?', 11], 'find the user with address #11')
  # reverse of a has_many :through
  assert_constraint_condition({:subscription => {:service => 5}}, ['services.id = ?', 5], 'find all users subscribed to service #5')
  assert(@test_object.active_scaffold_joins.include?({:subscription => :service}), 'multi-level association include')

  @test_object.active_scaffold_config = config_for('subscription')
  # belongs_to (vs has_one)
  assert_constraint_condition({:user => 2}, ['subscriptions.user_id = ?', 2], 'find the subscription for user #2')
  # belongs_to (vs has_many)
  assert_constraint_condition({:service => 1}, ['subscriptions.service_id = ?', 1], 'find all subscriptions for service #1')

  @test_object.active_scaffold_config = config_for('service')
  # has_many (vs belongs_to)
  assert_constraint_condition({:subscriptions => 10}, ['subscriptions.id = ?', 10], 'find the service with subscription #10')
  # has_many :through (through has_many)
  assert_constraint_condition({:users => 7}, ['users.id = ?', 7], 'find the service with user #7')

  @test_object.active_scaffold_config = config_for('address')
  # belongs_to :polymorphic => true
  @test_object.params[:parent_model] = 'User'
  assert_constraint_condition({:addressable => 14}, ['addresses.addressable_id = ?', 14, 'addresses.addressable_type = ?', 'User'], 'find all addresses for user #14')
end

#test_constraint_conditions_for_normal_attributesObject



160
161
162
163
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/misc/constraints_test.rb', line 160

def test_constraint_conditions_for_normal_attributes
  @test_object.active_scaffold_config = config_for('user')
  assert_constraint_condition({'foo' => 'bar'}, ['users.foo = ?', 'bar'], 'normal column-based constraint')
end