SlideShare uma empresa Scribd logo
1 de 14
Baixar para ler offline
Machinist-caching
        @tomas_stefano
    http://rubycasts.com.br
           SuccesSoft
             Nohup
Fixtures/factories/etc.

• Object Daddy (último commit em 2009 : )
• Factory Girl
• Machinist
• Fabrication
• Fixtures
Scenario
class Country < ActiveRecord::Base
  validates :name, presence: true, uniqueness: { allow_blank: true }
end

class State < ActiveRecord::Base
  validates :name, presence: true, uniqueness: { allow_blank: true }
end

class City < ActiveRecord::Base
  validates :name, presence: true, uniqueness: { allow_blank: true }
end
Scenario

Country.blueprint(:brasil) do
  name { 'Brasil sil sil!!' }
end
Scenario
State.blueprint(:minas_gerais) do
  name { 'Minas Gerais' }
  acronym { 'MG' }
  country { Country.make!(:brasil) }
end

State.blueprint(:rio_grande_do_sul) do
  name { 'Rio Grande do Sul' }
  acronym { 'RS' }
  country { Country.make!(:brasil) }
end
Scenario
City.blueprint(:belo_horizonte) do
  name { 'Belo Horizonte(Belzonte!)' }
  state { State.make!(:minas_gerais) }
end

City.blueprint(:porto_alegre) do
  name { 'Porto Alegre' }
  state { State.make!(:rio_grande_do_sul) }
end
Problema

City.make!(:belo_horizonte)
City.make!(:porto_alegre)
=> Country: Nome está em uso
# :S
Problema


brasil = Country.make!(:brasil)
mg = State.make!(:minas_gerais, country: brasil)
rs = State.make!(:rio_grande_do_sul, country: brasil)
City.make!(:belo_horizonte, state: mg)
City.make!(:porto_alegre, state: rs)
Parece que Algo está
      errado
Solução



gem install machinist-caching
RSpec

RSpec.configure do |config|
  config.before do
    Machinist::Caching::Shop.instance.reset!
  end
end
Test::unit

class Test::Unit::TestCase
 def setup
   Machinist::Caching::Shop.instance.reset!
 end
end
Pronto


City.make!(:belo_horizonte)
City.make!(:porto_alegre)
Obrigado!


    @tomas_stefano
http://rubycasts.com.br

Mais conteúdo relacionado

Machinist-caching

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n