Skip to content

Instantly share code, notes, and snippets.

@Fernan2
Created November 28, 2016 22:25
Show Gist options
  • Select an option

  • Save Fernan2/922436348898709f22aa84a73a54f490 to your computer and use it in GitHub Desktop.

Select an option

Save Fernan2/922436348898709f22aa84a73a54f490 to your computer and use it in GitHub Desktop.
Use temping to test tematizable
require 'rails_helper'
require 'temping'
Temping.create :bebedor do
include Tematizable
end
describe Tematizable do
let(:cerveza) { create(:tematica, nombre: 'cerveza') }
let(:whisky) { create(:tematica, nombre: 'whisky') }
describe '#fijar_tematicas!' do
context 'con un tematizable' do
let(:buddy) { Bebedor.create }
it 'debe permitir añadirle una tematización' do
buddy.fijar_tematicas!([cerveza.id])
expect(cerveza.tematizaciones.count).to eq 1
end
context 'con alguna tematica asignada' do
before do
create(:tematizacion, tematica: cerveza, tematizable: buddy)
create(:tematizacion, tematica: whisky, tematizable: buddy)
end
it 'debe permitir desuscribir todas' do
buddy.fijar_tematicas!([])
expect(cerveza.tematizaciones.count).to eq 0
end
it 'debe permitir desuscribir algunas' do
buddy.fijar_tematicas!([whisky.id])
expect(cerveza.tematizaciones.count).to eq 0
expect(whisky.tematizaciones.count).to eq 1
end
context 'con tematizaciones con grupo' do
before do
create(:tematizacion, tematica: cerveza, tematizable: buddy, tematizable_grupo: 'expertos')
end
it 'debe desuscribir del grupo pero no de otros grupos' do
buddy.fijar_tematicas!([whisky.id], 'expertos')
expect(cerveza.tematizaciones.count).to eq 1
expect(whisky.tematizaciones.count).to eq 2
expect(cerveza.tematizaciones.where(tematizable_grupo: 'expertos').count).to eq 0
expect(whisky.tematizaciones.where(tematizable_grupo: 'expertos').count).to eq 1
end
it 'debe permitir desuscribir todas en el grupo' do
buddy.fijar_tematicas!([], 'expertos')
expect(cerveza.tematizaciones.count).to eq 1
expect(whisky.tematizaciones.count).to eq 1
expect(cerveza.tematizaciones.where(tematizable_grupo: 'expertos').count).to eq 0
expect(whisky.tematizaciones.where(tematizable_grupo: 'expertos').count).to eq 0
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment