bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksarequire 'spec_helper'
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksadescribe SerializationsController do
7c7a19761235efff584ee65a1c6dc4aa1735ff64Eugen Kuksa let!(:user) { create :user }
7c7a19761235efff584ee65a1c6dc4aa1735ff64Eugen Kuksa let!(:language) { create :language, user: user }
7c7a19761235efff584ee65a1c6dc4aa1735ff64Eugen Kuksa let!(:serial) { create :serialization, language: language }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'signed in as owner' do
23305f217b86a2ebf90a848af9036908e0070542Eugen Kuksa before { sign_in user }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on get to show' do
23305f217b86a2ebf90a848af9036908e0070542Eugen Kuksa before { get :show, id: serial.id }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it { should respond_with :success }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it { should render_template :show }
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa it 'does not set the flash' do
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa expect(flash).to be_empty
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on get to new' do
23305f217b86a2ebf90a848af9036908e0070542Eugen Kuksa before { get :new }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it { should respond_with :success }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it { should render_template :new }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on POST to CREATE' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa before do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa post :create, serialization: {
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa name: 'test132',
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa mimetype: 'text',
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa language_id: language.id
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'create the record' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa let!(:serial_from_db) { Serialization.find_by_name('test132') }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'should exist' do
db149239590d2a39d399f12cd01609b190ea4763Eugen Kuksa expect(serial_from_db).not_to be(nil)
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'should have correct mime type' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa expect(serial_from_db.mimetype).to eq('text')
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'should have correct name' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa expect(serial_from_db.name).to eq('test132')
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on PUT to Update' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa before do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa put :update, id: serial.id, serialization: {
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa name: 'test4325',
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa mimetype: 'texttext' }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'change the record' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa let!(:serial_from_db) { Serialization.find_by_name('test4325') }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'should exist' do
db149239590d2a39d399f12cd01609b190ea4763Eugen Kuksa expect(serial_from_db).not_to be(nil)
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'should have correct mime type' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa expect(serial_from_db.mimetype).to eq('texttext')
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'should have correct name' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa expect(serial_from_db.name).to eq('test4325')
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on POST to DELETE' do
23305f217b86a2ebf90a848af9036908e0070542Eugen Kuksa before { delete :destroy, id: serial.id }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'remove the record' do
db149239590d2a39d399f12cd01609b190ea4763Eugen Kuksa expect(Serialization.find_by_id(serial.id)).to be(nil)
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on GET to EDIT' do
23305f217b86a2ebf90a848af9036908e0070542Eugen Kuksa before { get :edit, id: serial.id }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it { should respond_with :success }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it { should render_template :edit }
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa it 'does not set the flash' do
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa expect(flash).to be_empty
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'signed in as not-owner' do
7c7a19761235efff584ee65a1c6dc4aa1735ff64Eugen Kuksa let(:user2) { create :user }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa before { sign_in user2 }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on get to show' do
23305f217b86a2ebf90a848af9036908e0070542Eugen Kuksa before { get :show, id: serial.id }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it { should respond_with :success }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it { should render_template :show }
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa it 'does not set the flash' do
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa expect(flash).to be_empty
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on get to new' do
23305f217b86a2ebf90a848af9036908e0070542Eugen Kuksa before { get :new }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it { should respond_with :success }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it { should render_template :new }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on POST to CREATE' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa before do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa post :create, serialization: {
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa name: 'test132',
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa mimetype: 'text',
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa language_id: language.id }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'create the record' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa let!(:serial_from_db) { Serialization.find_by_name('test132') }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'should exist' do
db149239590d2a39d399f12cd01609b190ea4763Eugen Kuksa expect(serial_from_db).not_to be(nil)
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'should have correct mime type' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa expect(serial_from_db.mimetype).to eq('text')
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'should have correct name' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa expect(serial_from_db.name).to eq('test132')
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on PUT to Update' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa before do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa put :update, id: serial.id, serialization: {
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa name: 'test4325',
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa mimetype: 'texttext'
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'change the record' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa let!(:serial_from_db) { Serialization.find_by_name('test4325') }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'should exist' do
db149239590d2a39d399f12cd01609b190ea4763Eugen Kuksa expect(serial_from_db).not_to be(nil)
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'should have correct mime type' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa expect(serial_from_db.mimetype).to eq('texttext')
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'should have correct name' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa expect(serial_from_db.name).to eq('test4325')
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on POST to DELETE' do
23305f217b86a2ebf90a848af9036908e0070542Eugen Kuksa before { delete :destroy, id: serial.id }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'remove the record' do
db149239590d2a39d399f12cd01609b190ea4763Eugen Kuksa expect(Serialization.find_by_id(serial.id)).to be(nil)
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on GET to EDIT' do
23305f217b86a2ebf90a848af9036908e0070542Eugen Kuksa before { get :edit, id: serial.id }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it { should respond_with :success }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it { should render_template :edit }
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa it 'does not set the flash' do
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa expect(flash).to be_empty
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'not signed in' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on get to show' do
23305f217b86a2ebf90a848af9036908e0070542Eugen Kuksa before { get :show, id: serial.id, language_id: language.id }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it { should respond_with :success }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it { should render_template :show }
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa it 'does not set the flash' do
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa expect(flash).to be_empty
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on get to new' do
23305f217b86a2ebf90a848af9036908e0070542Eugen Kuksa before { get :new, language_id: language.id }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it { should respond_with :redirect }
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa it 'sets the flash' do
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa expect(flash[:alert]).to match(/not authorized/)
7ca38d75d045fade73b81bff6fdf34f4755d75fbEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on POST to CREATE' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa before do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa put :update, id: serial.id, serialization: {
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa name: 'test2',
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa mimetype: 'text',
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa language_id: language.id
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'not create the record' do
db149239590d2a39d399f12cd01609b190ea4763Eugen Kuksa expect(Serialization.find_by_name('test2')).to be(nil)
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on PUT to Update' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa before do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa put :update, id: serial.id, serialization: {
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa name: 'test2',
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa mimetype: 'text',
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa language_id: language.id
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'not change the record' do
db149239590d2a39d399f12cd01609b190ea4763Eugen Kuksa expect(Serialization.find_by_name('test2')).to be(nil)
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa context 'on POST to DELETE' do
23305f217b86a2ebf90a848af9036908e0070542Eugen Kuksa before { delete :destroy, id: serial.id }
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa it 'not remove the record' do
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa expect(Serialization.find_by_id(serial.id)).to eq(serial)
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksa end
bdc69d2e103b81dfabf3965a968cad610feecfffEugen Kuksaend