logic_mappings_controller_spec.rb revision 7ca38d75d045fade73b81bff6fdf34f4755d75fb
1078N/Arequire 'spec_helper'
970N/A
970N/Adescribe LogicMappingsController do
970N/A let!(:user) { create :user }
970N/A let!(:target_logic) { create :logic, user: user }
970N/A let!(:source_logic) { create :logic, user: user }
970N/A let!(:mapping) do
970N/A create :logic_mapping,
970N/A source: source_logic, target: target_logic, user: user
970N/A end
970N/A
970N/A context 'signed in as owner' do
970N/A before { sign_in user }
970N/A
970N/A context 'on get to show' do
970N/A before { get :show, id: mapping.to_param, logic_id: source_logic.id }
970N/A it { should respond_with :success }
970N/A it { should render_template :show }
970N/A
970N/A it 'does not set the flash' do
970N/A expect(flash).to be_empty
970N/A end
970N/A end
970N/A
970N/A context 'on get to new' do
970N/A before { get :new, logic_id: source_logic.id }
970N/A
970N/A it { should respond_with :success }
970N/A it { should render_template :new }
982N/A end
982N/A
982N/A context 'on POST to CREATE' do
982N/A before do
982N/A post :create, logic_id: source_logic.id,
982N/A logic_mapping: {
982N/A source_id: source_logic.id,
970N/A target_id: target_logic.id,
970N/A iri: 'http://test.de'
970N/A }
970N/A end
970N/A
970N/A context 'create the record' do
970N/A let!(:mapping_from_db) { LogicMapping.find_by_iri('http://test.de') }
970N/A
970N/A it 'should exist' do
970N/A expect(mapping_from_db).not_to be(nil)
970N/A end
970N/A
970N/A it 'should have correct source' do
970N/A expect(mapping_from_db.source).to eq(source_logic)
970N/A end
970N/A
970N/A it 'should have correct target' do
970N/A expect(mapping_from_db.target).to eq(target_logic)
1123N/A end
970N/A end
970N/A end
970N/A
970N/A context 'on PUT to Update' do
970N/A before do
970N/A put :update, logic_id: source_logic.id, id: mapping.to_param,
970N/A logic_mapping: {
970N/A source_id: source_logic.id,
970N/A target_id: target_logic.id,
970N/A iri: 'http://test2.de'
970N/A }
970N/A end
970N/A
970N/A context 'change the record' do
970N/A let!(:mapping_from_db) { LogicMapping.find_by_iri('http://test2.de') }
970N/A
970N/A it 'should exist' do
970N/A expect(mapping_from_db).not_to be(nil)
970N/A end
970N/A
970N/A it 'should have correct source' do
970N/A expect(mapping_from_db.source).to eq(source_logic)
970N/A end
970N/A
1123N/A it 'should have correct target' do
1123N/A expect(mapping_from_db.target).to eq(target_logic)
1123N/A end
970N/A end
970N/A end
970N/A
1123N/A context 'on POST to DELETE' do
970N/A before { delete :destroy, id: mapping.to_param, logic_id: source_logic.id }
970N/A
970N/A it 'remove the record' do
970N/A expect(LogicMapping.find_by_id(mapping.id)).to be(nil)
970N/A end
1123N/A end
970N/A
1123N/A context 'on GET to EDIT' do
1123N/A before { get :edit, id: mapping.to_param, logic_id: source_logic.id }
1123N/A it { should respond_with :success }
1123N/A it { should render_template :edit }
1123N/A
1123N/A it 'does not set the flash' do
970N/A expect(flash).to be_empty
970N/A end
970N/A end
970N/A end
970N/A
970N/A context 'signed in as not-owner' do
970N/A let!(:user2) { create :user }
970N/A before { sign_in user2 }
970N/A
970N/A context 'on get to show' do
970N/A before { get :show, id: mapping.to_param, logic_id: source_logic.id }
970N/A it { should respond_with :success }
970N/A it { should render_template :show }
970N/A
970N/A it 'does not set the flash' do
970N/A expect(flash).to be_empty
970N/A end
970N/A end
970N/A
970N/A context 'on get to new' do
970N/A before { get :new, logic_id: source_logic.id }
970N/A
970N/A it { should respond_with :success }
970N/A it { should render_template :new }
970N/A end
970N/A
970N/A context 'on POST to CREATE' do
970N/A before do
970N/A post :create, logic_id: source_logic.id,
970N/A logic_mapping: {
970N/A source_id: source_logic.id,
970N/A target_id: target_logic.id,
970N/A iri: 'http://test.de'
1078N/A }
970N/A end
970N/A
970N/A context 'create the record' do
970N/A let!(:mapping_from_db) { LogicMapping.find_by_iri('http://test.de') }
970N/A
970N/A it 'should exist' do
970N/A expect(mapping_from_db).not_to be(nil)
970N/A end
970N/A
970N/A it 'should have correct source' do
970N/A expect(mapping_from_db.source).to eq(source_logic)
970N/A end
970N/A
970N/A it 'should have correct target' do
970N/A expect(mapping_from_db.target).to eq(target_logic)
970N/A end
970N/A end
970N/A end
970N/A
1123N/A context 'on PUT to Update' do
970N/A before do
970N/A put :update, logic_id: source_logic.id, id: mapping.to_param,
970N/A logic_mapping: {
970N/A source_id: source_logic.id,
970N/A target_id: target_logic.id,
970N/A iri: 'http://test2.de'
970N/A }
970N/A end
970N/A
970N/A it 'not change the record' do
970N/A expect(LogicMapping.find_by_iri('http://test2.de')).to be(nil)
970N/A end
970N/A end
970N/A
970N/A context 'on POST to DELETE' do
970N/A before { delete :destroy, id: mapping.to_param, logic_id: source_logic.id }
it 'not remove the record' do
expect(LogicMapping.find_by_id(mapping.id)).to eq(mapping)
end
end
context 'on GET to EDIT' do
before { get :edit, id: mapping.to_param, logic_id: source_logic.id }
it { should respond_with :redirect }
it 'sets the flash' do
expect(flash[:alert]).to match(/not authorized/)
end
end
end
context 'not signed in' do
context 'on get to show' do
before { get :show, id: mapping.to_param, logic_id: source_logic.id }
it { should respond_with :success }
it { should render_template :show }
it 'does not set the flash' do
expect(flash).to be_empty
end
end
context 'on get to new' do
before { get :new, logic_id: source_logic.id }
it { should respond_with :redirect }
it 'sets the flash' do
expect(flash[:alert]).to match(/not authorized/)
end
end
end
context 'on POST to CREATE' do
before do
post :create, logic_id: source_logic.id,
logic_mapping: {
source_id: source_logic.id,
target_id: target_logic.id,
iri: 'http://test.de'
}
end
it 'not create the record' do
expect(LogicMapping.find_by_iri('http://test.de')).to be(nil)
end
end
context 'on PUT to Update' do
before do
put :update, logic_id: source_logic.id, id: mapping.to_param,
logic_mapping: {
source_id: source_logic.id,
target_id: target_logic.id,
iri: 'http://test2.de'
}
end
it 'not change the record' do
expect(LogicMapping.find_by_iri('http://test2.de')).to be(nil)
end
end
context 'on POST to DELETE' do
before { delete :destroy, id: mapping.to_param, logic_id: source_logic.id }
it 'not remove the record' do
expect(LogicMapping.find_by_id(mapping.id)).to eq(mapping)
end
end
end