Commit f52512e33452dba3a2dce6c339c4806a46685d7e

Authored by AntonioTerceiro
1 parent ad5360bb

ActionItem243: adding a sanity test for nested_has_many_through plugin



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1592 3f533792-8f58-4932-b0fe-aaf55b0a4547
vendor/plugins/nested_has_many_through/test/helper.rb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +require File.dirname(__FILE__) + '/../../../../config/environment'
  2 +load(File.dirname(__FILE__) + '/schema.rb')
  3 +
  4 +class Pub < ActiveRecord::Base
  5 + set_table_name :nested_has_many_through_pubs
  6 +end
  7 +
  8 +class City < ActiveRecord::Base
  9 + set_table_name :nested_has_many_through_cities
  10 + has_many :pubs
  11 +end
  12 +
  13 +class Country < ActiveRecord::Base
  14 + set_table_name :nested_has_many_through_countries
  15 + has_many :cities
  16 + has_many :pubs, :through => :cities
  17 +end
  18 +
  19 +class Planet < ActiveRecord::Base
  20 + set_table_name :nested_has_many_through_planets
  21 + has_many :countries
  22 + has_many :cities, :through => :countries
  23 + has_many :pubs, :through => :cities
  24 +end
... ...
vendor/plugins/nested_has_many_through/test/nested_has_many_through_test.rb
1 1 require 'test/unit'
  2 +require File.join(File.dirname(__FILE__), 'helper')
2 3  
3 4 class NestedHasManyThroughTest < Test::Unit::TestCase
4   - # Replace this with your real tests.
5   - def test_this_plugin
6   - flunk
  5 +
  6 + def test_nested_has_many_through
  7 +
  8 + planet = Planet.create!
  9 + pubs = []
  10 + 2.times do
  11 + planet.countries.build.save!
  12 + planet.countries.each do |country|
  13 + 2.times do
  14 + country.cities.build.save!
  15 + end
  16 + country.cities.each do |city|
  17 + pubs << city.pubs.build
  18 + pubs.last.save!
  19 + end
  20 + end
  21 + end
  22 +
  23 + assert_equal pubs, planet.pubs
  24 +
7 25 end
8 26 end
... ...
vendor/plugins/nested_has_many_through/test/schema.rb 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +ActiveRecord::Schema.define(:version => 0) do
  2 +
  3 + create_table "nested_has_many_through_cities", :force => true do |t|
  4 + t.string "name"
  5 + t.integer "country_id"
  6 + t.datetime "created_at"
  7 + t.datetime "updated_at"
  8 + end
  9 +
  10 + create_table "nested_has_many_through_countries", :force => true do |t|
  11 + t.string "name"
  12 + t.integer "planet_id"
  13 + t.datetime "created_at"
  14 + t.datetime "updated_at"
  15 + end
  16 +
  17 + create_table "nested_has_many_through_planets", :force => true do |t|
  18 + t.string "name"
  19 + t.datetime "created_at"
  20 + t.datetime "updated_at"
  21 + end
  22 +
  23 + create_table "nested_has_many_through_pubs", :force => true do |t|
  24 + t.string "name"
  25 + t.integer "city_id"
  26 + t.datetime "created_at"
  27 + t.datetime "updated_at"
  28 + end
  29 +
  30 +end
... ...