logic_mappings_controller_spec.rb revision 9721f58c0c6959fae3a048672ad4eacc6a1123e7
4623N/Arequire 'spec_helper'
4070N/A
6033N/Adescribe LogicMappingsController do
4070N/A let!(:user) { FactoryGirl.create :user }
4070N/A let!(:target_logic) { FactoryGirl.create :logic, user: user }
4070N/A let!(:source_logic) { FactoryGirl.create :logic, user: user }
4070N/A let!(:mapping) do
4070N/A FactoryGirl.create :logic_mapping,
4070N/A source: source_logic, target: target_logic, user: user
4070N/A end
4070N/A
4070N/A context 'signed in as owner' do
4070N/A before { sign_in user }
4070N/A
4070N/A context 'on get to show' do
4070N/A before do
4070N/A get :show, id: mapping.id, logic_id: source_logic.id
4070N/A end
4070N/A it { should respond_with :success }
4070N/A it { should render_template :show }
4070N/A it { should_not set_the_flash }
4070N/A end
4070N/A
4070N/A context 'on get to new' do
4070N/A before do
4070N/A get :new, logic_id: source_logic.id
4312N/A end
4312N/A
4070N/A it { should respond_with :success }
4070N/A it { should render_template :new }
4070N/A end
6033N/A
6033N/A context 'on POST to CREATE' do
6033N/A before do
6033N/A post :create, logic_id: source_logic.id,
6033N/A logic_mapping: {
6033N/A source_id: source_logic.id,
6033N/A target_id: target_logic.id,
6033N/A iri: 'http://test.de'
4070N/A }
4070N/A end
4312N/A
6033N/A context 'create the record' do
4312N/A let!(:mapping_from_db) { LogicMapping.find_by_iri('http://test.de') }
4312N/A
4312N/A it 'should exist' do
4312N/A expect(mapping_from_db).not_to be_nil
4312N/A end
4312N/A
4312N/A it 'should have correct source' do
4312N/A expect(mapping_from_db.source).to eq(source_logic)
6033N/A end
4070N/A
4312N/A it 'should have correct target' do
4312N/A expect(mapping_from_db.target).to eq(target_logic)
4312N/A end
4312N/A end
4312N/A end
4312N/A
4312N/A context 'on PUT to Update' do
4312N/A before do
4070N/A put :update, logic_id: source_logic.id, id: mapping.id,
4070N/A logic_mapping: {
4070N/A source_id: source_logic.id,
4070N/A target_id: target_logic.id,
4070N/A iri: 'http://test2.de'
4070N/A }
4070N/A end
4070N/A
4070N/A context 'change the record' do
4070N/A let!(:mapping_from_db) { LogicMapping.find_by_iri('http://test2.de') }
4070N/A
4070N/A it 'should exist' do
4070N/A expect(mapping_from_db).not_to be_nil
4070N/A end
4070N/A
4070N/A it 'should have correct source' do
4070N/A expect(mapping_from_db.source).to eq(source_logic)
4070N/A end
4070N/A
4070N/A it 'should have correct target' do
4070N/A expect(mapping_from_db.target).to eq(target_logic)
4665N/A end
4070N/A end
4070N/A end
4070N/A
4312N/A context 'on POST to DELETE' do
4312N/A before do
4312N/A delete :destroy, id: mapping.id, logic_id: source_logic.id
4312N/A end
4070N/A
6033N/A it 'remove the record' do
6033N/A expect(LogicMapping.find_by_id(mapping.id)).to be_nil
6033N/A end
4312N/A end
4312N/A
6033N/A context 'on GET to EDIT' do
6033N/A before do
4070N/A get :edit, id: mapping.id, logic_id: source_logic.id
4070N/A end
4070N/A it { should respond_with :success }
4070N/A it { should render_template :edit }
6033N/A it { should_not set_the_flash }
6033N/A end
6033N/A end
6033N/A
6033N/A context 'signed in as not-owner' do
6033N/A let!(:user2) { FactoryGirl.create :user }
6033N/A before { sign_in user2 }
6033N/A
6033N/A context 'on get to show' do
4665N/A before do
4070N/A get :show, id: mapping.id, logic_id: source_logic.id
4070N/A end
4070N/A it { should respond_with :success }
4070N/A it { should render_template :show }
4070N/A it { should_not set_the_flash }
4070N/A end
4070N/A
4070N/A context 'on get to new' do
4070N/A before do
4070N/A get :new, logic_id: source_logic.id
4070N/A end
4070N/A
4070N/A it { should respond_with :success }
4312N/A it { should render_template :new }
4312N/A end
4070N/A
4070N/A context 'on POST to CREATE' do
4070N/A before do
4070N/A post :create, logic_id: source_logic.id,
4070N/A logic_mapping: {
source_id: source_logic.id,
target_id: target_logic.id,
iri: 'http://test.de'
}
end
context 'create the record' do
let!(:mapping_from_db) { LogicMapping.find_by_iri('http://test.de') }
it 'should exist' do
expect(mapping_from_db).not_to be_nil
end
it 'should have correct source' do
expect(mapping_from_db.source).to eq(source_logic)
end
it 'should have correct target' do
expect(mapping_from_db.target).to eq(target_logic)
end
end
end
context 'on PUT to Update' do
before do
put :update, logic_id: source_logic.id, id: mapping.id,
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 do
delete :destroy, id: mapping.id, logic_id: source_logic.id
end
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 do
get :edit, id: mapping.id, logic_id: source_logic.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: mapping.id, logic_id: source_logic.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, logic_id: source_logic.id
end
it { should respond_with :redirect }
it { should set_the_flash }
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.id,
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 do
delete :destroy, id: mapping.id, logic_id: source_logic.id
end
it 'not remove the record' do
expect(LogicMapping.find_by_id(mapping.id)).to eq(mapping)
end
end
end