Module: FixtureFarm::ActiveRecordExtension
- Defined in:
- lib/fixture_farm/active_record_extension.rb
Instance Method Summary collapse
- #candidate_fixtures_file_path ⇒ Object
- #existing_fixtures_file_path ⇒ Object
- #fixture_name ⇒ Object
- #fixtures_file_path ⇒ Object
Instance Method Details
#candidate_fixtures_file_path ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/fixture_farm/active_record_extension.rb', line 20 def candidate_fixtures_file_path klass = self.class loop do path = Rails.root.join('test', 'fixtures', "#{klass.to_s.underscore.pluralize}.yml") return path if klass >= ActiveRecord::Base || !klass.columns.map(&:name).include?(klass.inheritance_column) klass = klass.superclass end end |
#existing_fixtures_file_path ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fixture_farm/active_record_extension.rb', line 30 def existing_fixtures_file_path klass = self.class while klass < ActiveRecord::Base path = Rails.root.join('test', 'fixtures', "#{klass.to_s.underscore.pluralize}.yml") return path if File.exist?(path) klass = klass.superclass end nil end |
#fixture_name ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fixture_farm/active_record_extension.rb', line 5 def fixture_name require 'active_record/fixtures' return nil unless File.exist?(fixtures_file_path) fixtures = YAML.load_file(fixtures_file_path, permitted_classes: [ActiveSupport::HashWithIndifferentAccess]) fixtures.keys.find do |key| ActiveRecord::FixtureSet.identify(key) == id end end |
#fixtures_file_path ⇒ Object
16 17 18 |
# File 'lib/fixture_farm/active_record_extension.rb', line 16 def fixtures_file_path existing_fixtures_file_path || candidate_fixtures_file_path end |