Methods
- N
- T
-
- test_attributes,
- test_binary_in_fixtures,
- test_broken_yaml_exception,
- test_clean_fixtures,
- test_complete_instantiation,
- test_create_fixtures,
- test_create_symbol_fixtures,
- test_dirty_dirty_yaml_file,
- test_empty_yaml_fixture,
- test_empty_yaml_fixture_with_a_comment_in_it,
- test_erb_in_fixtures,
- test_fixtures,
- test_fixtures_are_set_up_with_database_env_variable,
- test_fixtures_from_root_yml_with_instantiation,
- test_insert_with_datetime,
- test_inserts,
- test_inserts_with_pre_and_suffix,
- test_instantiation,
- test_logger_level_invariant,
- test_multiple_clean_fixtures,
- test_nonexistent_fixture_file,
- test_omap_fixtures,
- test_serialized_fixtures,
- test_subsubdir_file_with_arbitrary_name,
- test_yaml_file_with_invalid_column,
- test_yaml_file_with_symbol_columns,
- test_yml_file_in_subdirectory
Constants
| FIXTURES | = | %w( accounts binaries companies customers developers developers_projects entrants movies projects subscribers topics tasks ) |
| MATCH_ATTRIBUTE_NAME | = | /[a-zA-Z][-\w]*/ |
Class Public methods
name()
Link
Instance Public methods
test_attributes()
Link
test_binary_in_fixtures()
Link
test_broken_yaml_exception()
Link
# File activerecord/test/cases/fixtures_test.rb, line 55 def test_broken_yaml_exception badyaml = Tempfile.new ['foo', '.yml'] badyaml.write 'a: : ' badyaml.flush dir = File.dirname badyaml.path name = File.basename badyaml.path, '.yml' assert_raises(ActiveRecord::Fixture::FormatError) do ActiveRecord::FixtureSet.create_fixtures(dir, name) end ensure badyaml.close badyaml.unlink end
test_clean_fixtures()
Link
# File activerecord/test/cases/fixtures_test.rb, line 42 def test_clean_fixtures FIXTURES.each do |name| fixtures = nil assert_nothing_raised { fixtures = create_fixtures(name).first } assert_kind_of(ActiveRecord::FixtureSet, fixtures) fixtures.each { |_name, fixture| fixture.each { |key, value| assert_match(MATCH_ATTRIBUTE_NAME, key) } } end end
test_complete_instantiation()
Link
test_create_fixtures()
Link
# File activerecord/test/cases/fixtures_test.rb, line 70 def test_create_fixtures fixtures = ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, "parrots") assert Parrot.find_by_name('Curious George'), 'George is not in the database' assert fixtures.detect { |f| f.name == 'parrots' }, "no fixtures named 'parrots' in #{fixtures.map(&:name).inspect}" end
test_create_symbol_fixtures()
Link
# File activerecord/test/cases/fixtures_test.rb, line 83 def test_create_symbol_fixtures fixtures = ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, :collections, :collections => Course) { Course.connection } assert Course.find_by_name('Collection'), 'course is not in the database' assert fixtures.detect { |f| f.name == 'collections' }, "no fixtures named 'collections' in #{fixtures.map(&:name).inspect}" end
test_dirty_dirty_yaml_file()
Link
test_empty_yaml_fixture()
Link
test_empty_yaml_fixture_with_a_comment_in_it()
Link
test_erb_in_fixtures()
Link
test_fixtures()
Link
test_fixtures_are_set_up_with_database_env_variable()
Link
# File activerecord/test/cases/fixtures_test.rb, line 263 def test_fixtures_are_set_up_with_database_env_variable db_url_tmp = ENV['DATABASE_URL'] ENV['DATABASE_URL'] = "sqlite3::memory:" ActiveRecord::Base.stubs(:configurations).returns({}) test_case = Class.new(ActiveRecord::TestCase) do fixtures :accounts def test_fixtures assert accounts(:signals37) end end result = test_case.new(:test_fixtures).run assert result.passed?, "Expected #{result.name} to pass:\n#{result}" ensure ENV['DATABASE_URL'] = db_url_tmp end
test_fixtures_from_root_yml_with_instantiation()
Link
test_insert_with_datetime()
Link
test_inserts()
Link
# File activerecord/test/cases/fixtures_test.rb, line 96 def test_inserts create_fixtures("topics") first_row = ActiveRecord::Base.connection.select_one("SELECT * FROM topics WHERE author_name = 'David'") assert_equal("The First Topic", first_row["title"]) second_row = ActiveRecord::Base.connection.select_one("SELECT * FROM topics WHERE author_name = 'Mary'") assert_nil(second_row["author_email_address"]) end
test_inserts_with_pre_and_suffix()
Link
# File activerecord/test/cases/fixtures_test.rb, line 106 def test_inserts_with_pre_and_suffix # Reset cache to make finds on the new table work ActiveRecord::FixtureSet.reset_cache ActiveRecord::Base.connection.create_table :prefix_other_topics_suffix do |t| t.column :title, :string t.column :author_name, :string t.column :author_email_address, :string t.column :written_on, :datetime t.column :bonus_time, :time t.column :last_read, :date t.column :content, :string t.column :approved, :boolean, :default => true t.column :replies_count, :integer, :default => 0 t.column :parent_id, :integer t.column :type, :string, :limit => 50 end # Store existing prefix/suffix old_prefix = ActiveRecord::Base.table_name_prefix old_suffix = ActiveRecord::Base.table_name_suffix # Set a prefix/suffix we can test against ActiveRecord::Base.table_name_prefix = 'prefix_' ActiveRecord::Base.table_name_suffix = '_suffix' other_topic_klass = Class.new(ActiveRecord::Base) do def self.name "OtherTopic" end end topics = [create_fixtures("other_topics")].flatten.first # This checks for a caching problem which causes a bug in the fixtures # class-level configuration helper. assert_not_nil topics, "Fixture data inserted, but fixture objects not returned from create" first_row = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_other_topics_suffix WHERE author_name = 'David'") assert_not_nil first_row, "The prefix_other_topics_suffix table appears to be empty despite create_fixtures: the row with author_name = 'David' was not found" assert_equal("The First Topic", first_row["title"]) second_row = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_other_topics_suffix WHERE author_name = 'Mary'") assert_nil(second_row["author_email_address"]) assert_equal :prefix_other_topics_suffix, topics.table_name.to_sym # This assertion should preferably be the last in the list, because calling # other_topic_klass.table_name sets a class-level instance variable assert_equal :prefix_other_topics_suffix, other_topic_klass.table_name.to_sym ensure # Restore prefix/suffix to its previous values ActiveRecord::Base.table_name_prefix = old_prefix ActiveRecord::Base.table_name_suffix = old_suffix ActiveRecord::Base.connection.drop_table :prefix_other_topics_suffix rescue nil end
test_instantiation()
Link
test_logger_level_invariant()
Link
test_multiple_clean_fixtures()
Link
# File activerecord/test/cases/fixtures_test.rb, line 76 def test_multiple_clean_fixtures fixtures_array = nil assert_nothing_raised { fixtures_array = create_fixtures(*FIXTURES) } assert_kind_of(Array, fixtures_array) fixtures_array.each { |fixtures| assert_kind_of(ActiveRecord::FixtureSet, fixtures) } end
test_nonexistent_fixture_file()
Link
# File activerecord/test/cases/fixtures_test.rb, line 203 def test_nonexistent_fixture_file nonexistent_fixture_path = FIXTURES_ROOT + "/imnothere" #sanity check to make sure that this file never exists assert Dir[nonexistent_fixture_path+"*"].empty? assert_raise(Errno::ENOENT) do ActiveRecord::FixtureSet.new( Account.connection, "companies", Company, nonexistent_fixture_path) end end
test_omap_fixtures()
Link
# File activerecord/test/cases/fixtures_test.rb, line 231 def test_omap_fixtures assert_nothing_raised do fixtures = ActiveRecord::FixtureSet.new(Account.connection, 'categories', Category, FIXTURES_ROOT + "/categories_ordered") fixtures.each.with_index do |(name, fixture), i| assert_equal "fixture_no_#{i}", name assert_equal "Category #{i}", fixture['name'] end end end
test_serialized_fixtures()
Link
test_subsubdir_file_with_arbitrary_name()
Link
# File activerecord/test/cases/fixtures_test.rb, line 247 def test_subsubdir_file_with_arbitrary_name assert_equal(categories(:sub_special_3).name, "A special category in an arbitrarily named subsubdir file") assert_equal(categories(:sub_special_3).class, SpecialCategory) end
test_yaml_file_with_invalid_column()
Link
# File activerecord/test/cases/fixtures_test.rb, line 220 def test_yaml_file_with_invalid_column e = assert_raise(ActiveRecord::Fixture::FixtureError) do ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT + "/naked/yml", "parrots") end assert_equal(%Q(table "parrots" has no column named "arrr".), e.message) end
test_yaml_file_with_symbol_columns()
Link
test_yml_file_in_subdirectory()
Link