Class: RailsBestPractices::Checks::IsolateSeedDataCheck

### Home Classes Methods

### In Files

- lib/rails_best_practices/checks/isolate_seed_data_check.rb

### Parent

RailsBestPractices::Checks::Check

### Methods

- ::new
- #evaluate_start
- #interesting_files
- #interesting_nodes

### Files

- LICENSE

### Class/Module Index

Quicksearch

- RailsBestPractices
- RailsBestPractices::Checks
- RailsBestPractices::Checks::AddModelVirtualAttributeCheck
- RailsBestPractices::Checks::AlwaysAddDbIndexCheck
- RailsBestPractices::Checks::Check
- RailsBestPractices::Checks::IsolateSeedDataCheck
- RailsBestPractices::Checks::KeepFindersOnTheirOwnModelCheck
- RailsBestPractices::Checks::LawOfDemeterCheck
- RailsBestPractices::Checks::ManyToManyCollectionCheck
- RailsBestPractices::Checks::MoveCodeIntoControllerCheck
- RailsBestPractices::Checks::MoveCodeIntoHelperCheck
- RailsBestPractices::Checks::MoveCodeIntoModelCheck
- RailsBestPractices::Checks::MoveFinderToNamedScopeCheck
- RailsBestPractices::Checks::MoveModelLogicIntoModelCheck
- RailsBestPractices::Checks::NeedlessDeepNestingCheck
- RailsBestPractices::Checks::NestedModelFormsCheck
- RailsBestPractices::Checks::NotUseDefaultRouteCheck
- RailsBestPractices::Checks::OveruseRouteCustomizationsCheck
- RailsBestPractices::Checks::ReplaceComplexCreationWithFactoryMethodCheck
- RailsBestPractices::Checks::ReplaceInstanceVariableWithLocalVariableCheck
- RailsBestPractices::Checks::UseBeforeFilterCheck
- RailsBestPractices::Checks::UseModelAssociationCheck
- RailsBestPractices::Checks::UseModelCallbackCheck
- RailsBestPractices::Checks::UseObserverCheck
- RailsBestPractices::Checks::UseScopeAccessCheck
- RailsBestPractices::Core
- RailsBestPractices::Core::CheckingVisitor
- RailsBestPractices::Core::Error
- RailsBestPractices::Core::Runner
- Enumerable
- NilClass
- Sexp
- String

No matching classes.

# RailsBestPractices::Checks::IsolateSeedDataCheck

Check a migration file to make sure not to insert data in migration, move them to seed file.

Implementation: check if there are :create, :create!, and :new with :save or :save! exist, the migration file needs isolate seed data.

### Public Class Methods

new() click to toggle source

    # File lib/rails_best_practices/checks/isolate_seed_data_check.rb, line 18
    def initialize
      super
      @new_variables = []
      @files = []
      @parse = false
    end

### Public Instance Methods

evaluate_start(node) click to toggle source

    # File lib/rails_best_practices/checks/isolate_seed_data_check.rb, line 25
    def evaluate_start(node)
      # check duplicate migration because of always_add_db_index_check.
      if :defs == node.node_type
        if @files.include? node.file
          @parse = true if :up == node.message
        else
          @files << node.file
        end
      end

      if @parse
        if [:create, :create!].include? node.message
          add_error("isolate seed data")
        elsif :lasgn == node.node_type
          remember_new_variable(node)
        elsif [:save, :save!].include? node.message
          add_error("isolate seed data") if new_record?(node)
        end
      end
    end

interesting_files() click to toggle source

    # File lib/rails_best_practices/checks/isolate_seed_data_check.rb, line 14
    def interesting_files
      MIGRATION_FILES
    end

interesting_nodes() click to toggle source

    # File lib/rails_best_practices/checks/isolate_seed_data_check.rb, line 10
    def interesting_nodes
      [:defs, :call, :lasgn]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.