language_adjoint_controller_spec.rb revision 23305f217b86a2ebf90a848af9036908e0070542
327N/Arequire 'spec_helper'
327N/A
327N/Adescribe LanguageAdjointsController do
327N/A let!(:source) { FactoryGirl.create(:logic) }
327N/A let!(:target) { FactoryGirl.create(:logic) }
327N/A let!(:mapping) do
327N/A FactoryGirl.create(:logic_mapping, source: source, target: target)
327N/A end
327N/A
327N/A let!(:user) { FactoryGirl.create :user }
327N/A let!(:target_language) { FactoryGirl.create :language, user: user }
327N/A let!(:source_language) { FactoryGirl.create :language, user: user }
327N/A let!(:mapping) do
327N/A FactoryGirl.create :language_mapping,
327N/A source: source_language, target: target_language, user: user
327N/A end
327N/A let!(:target_language2) { FactoryGirl.create :language, user: user }
327N/A let!(:source_language2) { FactoryGirl.create :language, user: user }
327N/A let!(:mapping2) do
327N/A FactoryGirl.create :language_mapping,
327N/A source: source_language2, target: target_language2, user: user
327N/A end
3976N/A let!(:adjoint) do
327N/A FactoryGirl.create :language_adjoint,
327N/A translation: mapping, projection: mapping2, user: user
327N/A end
327N/A
864N/A context 'signed in as owner' do
864N/A before { sign_in user }
327N/A
824N/A context 'on get to show' do
327N/A before { get :show, id: adjoint.id, mapping_id: mapping.id }
618N/A it { should respond_with :success }
327N/A it { should render_template :show }
844N/A it { should_not set_the_flash }
844N/A end
327N/A
1273N/A context 'on get to new' do
327N/A before { get :new, mapping_id: mapping.id }
3661N/A
3661N/A it { should respond_with :success }
3996N/A it { should render_template :new }
3996N/A end
3996N/A
327N/A context 'on POST to CREATE' do
327N/A before do
327N/A post :create, language_mapping_id: mapping.id, language_adjoint: {
327N/A translation_id: mapping.id,
327N/A projection_id: mapping2.id,
327N/A iri: 'http://test.de'
327N/A }
327N/A end
327N/A
327N/A context 'create the record' do
327N/A let!(:adjoint_from_db) { LanguageAdjoint.find_by_iri('http://test.de') }
327N/A
327N/A it 'should exist' do
327N/A expect(adjoint_from_db).not_to be_nil
327N/A end
327N/A
327N/A it 'should have correct translation' do
327N/A expect(adjoint_from_db.translation).to eq(mapping)
327N/A end
327N/A
824N/A it 'should have correct projection' do
327N/A expect(adjoint_from_db.projection).to eq(mapping2)
327N/A end
327N/A end
327N/A end
327N/A
327N/A context 'on PUT to Update' do
327N/A before do
327N/A put :update, id: adjoint.id, language_adjoint: {
327N/A translation_id: mapping.id,
327N/A projection_id: mapping2.id,
327N/A iri: 'http://test2.de'
327N/A }
327N/A end
327N/A
327N/A context 'change the record' do
327N/A let!(:adjoint_from_db) { LanguageAdjoint.find_by_iri('http://test2.de') }
327N/A
327N/A it 'should exist' do
327N/A expect(adjoint_from_db).not_to be_nil
3996N/A end
3996N/A
3996N/A it 'should have correct translation' do
3996N/A expect(adjoint_from_db.translation).to eq(mapping)
3996N/A end
3996N/A
3996N/A it 'should have correct projection' do
3996N/A expect(adjoint_from_db.projection).to eq(mapping2)
3996N/A end
3996N/A end
3996N/A end
context 'on POST to DELETE' do
before { delete :destroy, id: adjoint.id, mapping_id: mapping.id }
it 'remove the record' do
expect(LanguageAdjoint.find_by_id(adjoint.id)).to be_nil
end
end
context 'on GET to EDIT' do
before { get :edit, id: adjoint.id, mapping_id: mapping.id }
it { should respond_with :success }
it { should render_template :edit }
it { should_not set_the_flash }
end
end
context 'signed in as not-owner' do
let!(:user2) { FactoryGirl.create :user }
before { sign_in user2 }
context 'on get to show' do
before { get :show, id: adjoint.id, mapping_id: mapping.id }
it { should respond_with :success }
it { should render_template :show }
it { should_not set_the_flash }
end
context 'on get to new' do
before { get :new, mapping_id: mapping.id }
it { should respond_with :success }
it { should render_template :new }
end
context 'on POST to CREATE' do
before do
post :create, language_mapping_id: mapping.id, language_adjoint: {
translation_id: mapping.id,
projection_id: mapping2.id,
iri: 'http://test.de'
}
end
context 'create the record' do
let!(:adjoint_from_db) { LanguageAdjoint.find_by_iri('http://test.de') }
it 'should exist' do
expect(adjoint_from_db).not_to be_nil
end
it 'should have correct translation' do
expect(adjoint_from_db.translation).to eq(mapping)
end
it 'should have correct projection' do
expect(adjoint_from_db.projection).to eq(mapping2)
end
end
end
context 'on PUT to Update' do
before do
put :update, id: adjoint.id, language_adjoint: {
translation_id: mapping.id,
projection_id: mapping2.id,
iri: "http://test2.de"
}
end
it 'not change the record' do
expect(LanguageAdjoint.find_by_iri('http://test2.de')).to be_nil
end
end
context 'on POST to DELETE' do
before { delete :destroy, id: adjoint.id, translation_id: mapping.id }
it 'not remove the record' do
expect(LanguageAdjoint.find_by_id(adjoint.id)).to eq(adjoint)
end
end
context 'on GET to EDIT' do
before { get :edit, id: adjoint.id, translation_id: mapping.id }
it { should respond_with :redirect }
it { should set_the_flash.to(/not authorized/i) }
end
end
context 'not signed in' do
context 'on get to show' do
before { get :show, id: adjoint.id, translation_id: mapping.id }
it { should respond_with :success }
it { should render_template :show }
it { should_not set_the_flash }
end
context 'on get to new' do
before { get :new, translation_id: mapping.id }
it { should respond_with :redirect }
it { should set_the_flash }
end
context 'on POST to CREATE' do
before do
post :create, language_mapping_id: mapping.id, language_adjoint: {
translation_id: mapping.id,
projection_id: mapping2.id,
iri: 'http://test.de'
}
end
it 'not create the record' do
expect(LanguageAdjoint.find_by_iri("http://test.de")).to be_nil
end
end
context 'on PUT to Update' do
before do
put :update, id: adjoint.id, language_adjoint: {
translation_id: mapping.id,
projection_id: mapping2.id,
iri: 'http://test2.de'
}
end
it 'not change the record' do
expect(LanguageAdjoint.find_by_iri('http://test2.de')).to be_nil
end
end
context 'on POST to DELETE' do
before { delete :destroy, id: adjoint.id, translation_id: mapping.id }
it 'not remove the record' do
expect(LanguageAdjoint.find_by_id(adjoint.id)).to eq(adjoint)
end
end
end
end