language_adjoint_controller_spec.rb revision 1ffc4fc0f3b09d35eb82399725ff3ace12969bfc
98N/Arequire 'spec_helper'
98N/A
98N/Adescribe LanguageAdjointsController do
98N/A let!(:source) { FactoryGirl.create(:logic) }
98N/A let!(:target) { FactoryGirl.create(:logic) }
98N/A let!(:mapping) do
98N/A FactoryGirl.create(:logic_mapping, source: source, target: target)
98N/A end
98N/A
98N/A let!(:user) { FactoryGirl.create :user }
98N/A let!(:target_language) { FactoryGirl.create :language, user: user }
98N/A let!(:source_language) { FactoryGirl.create :language, user: user }
98N/A let!(:mapping) do
98N/A FactoryGirl.create :language_mapping,
98N/A source: source_language, target: target_language, user: user
98N/A end
98N/A let!(:target_language2) { FactoryGirl.create :language, user: user }
98N/A let!(:source_language2) { FactoryGirl.create :language, user: user }
98N/A let!(:mapping2) do
98N/A FactoryGirl.create :language_mapping,
98N/A source: source_language2, target: target_language2, user: user
98N/A end
98N/A let!(:adjoint) do
98N/A FactoryGirl.create :language_adjoint,
98N/A translation: mapping, projection: mapping2, user: user
98N/A end
98N/A
98N/A context 'signed in as owner' do
98N/A before { sign_in user }
98N/A
98N/A context 'on get to show' do
98N/A before do
98N/A get :show, id: adjoint.id, mapping_id: mapping.id
98N/A end
98N/A it { should respond_with :success }
98N/A it { should render_template :show }
98N/A it { should_not set_the_flash }
98N/A end
98N/A
98N/A context 'on get to new' do
98N/A before do
98N/A get :new, mapping_id: mapping.id
98N/A end
98N/A
98N/A it { should respond_with :success }
98N/A it { should render_template :new }
98N/A end
98N/A
98N/A context 'on POST to CREATE' do
98N/A before do
98N/A post :create, language_mapping_id: mapping.id, language_adjoint: {
98N/A translation_id: mapping.id,
98N/A projection_id: mapping2.id,
98N/A iri: 'http://test.de'
98N/A }
98N/A end
98N/A
98N/A context 'create the record' do
98N/A let!(:adjoint_from_db) { LanguageAdjoint.find_by_iri('http://test.de') }
98N/A
98N/A it 'should exist' do
98N/A expect(adjoint_from_db).not_to be_nil
98N/A end
98N/A
98N/A it 'should have correct translation' do
98N/A expect(adjoint_from_db.translation).to eq(mapping)
98N/A end
98N/A
98N/A it 'should have correct projection' do
98N/A expect(adjoint_from_db.projection).to eq(mapping2)
98N/A end
98N/A end
98N/A end
98N/A
98N/A context 'on PUT to Update' do
98N/A before do
98N/A put :update, id: adjoint.id, language_adjoint: {
98N/A translation_id: mapping.id,
98N/A projection_id: mapping2.id,
98N/A iri: 'http://test2.de'
98N/A }
98N/A end
98N/A
98N/A context 'change the record' do
let!(:adjoint_from_db) { LanguageAdjoint.find_by_iri('http://test2.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 POST to DELETE' do
before do
delete :destroy, id: adjoint.id, mapping_id: mapping.id
end
it 'remove the record' do
expect(LanguageAdjoint.find_by_id(adjoint.id)).to be_nil
end
end
context 'on GET to EDIT' do
before do
get :edit, id: adjoint.id, mapping_id: mapping.id
end
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 do
get :show, id: adjoint.id, mapping_id: mapping.id
end
it { should respond_with :success }
it { should render_template :show }
it { should_not set_the_flash }
end
context 'on get to new' do
before do
get :new, mapping_id: mapping.id
end
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 do
delete :destroy, id: adjoint.id, translation_id: mapping.id
end
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 do
get :edit, id: adjoint.id, translation_id: mapping.id
end
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 do
get :show, id: adjoint.id, translation_id: mapping.id
end
it { should respond_with :success }
it { should render_template :show }
it { should_not set_the_flash }
end
context 'on get to new' do
before do
get :new, translation_id: mapping.id
end
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 do
delete :destroy, id: adjoint.id, translation_id: mapping.id
end
it 'not remove the record' do
expect(LanguageAdjoint.find_by_id(adjoint.id)).to eq(adjoint)
end
end
end
end