language_mapping_controller_test.rb revision eeb6f931aa04060091972e9e7c163edc1d20b506
0N/Arequire 'test_helper'
0N/A
0N/Aclass LanguageMappingsControllerTest < ActionController::TestCase
0N/A
0N/A should_map_nested_resources :languages, :language_mappings,
0N/A :except => [:index]
0N/A
0N/A context 'language Mappings:' do
0N/A setup do
0N/A @user = FactoryGirl.create :user
0N/A @target_language = FactoryGirl.create :language, :user => @user
0N/A @source_language = FactoryGirl.create :language, :user => @user
0N/A @mapping = FactoryGirl.create :language_mapping, :source => @source_language, :target => @target_language, :user => @user
0N/A end
0N/A
0N/A context 'signed in as owner' do
0N/A setup do
0N/A sign_in @user
1105N/A end
0N/A
0N/A context 'on get to show' do
0N/A setup do
0N/A get :show, :id => @mapping.id, :language_id => @source_language.id
58N/A end
0N/A should respond_with :success
0N/A should assign_to :language_mapping
144N/A should render_template :show
144N/A should_not set_the_flash
144N/A end
144N/A
0N/A context 'on get to new' do
7N/A setup do
731N/A get :new, :language_id => @source_language.id
0N/A end
144N/A
731N/A should respond_with :success
0N/A should render_template :new
0N/A end
144N/A
144N/A context 'on POST to CREATE' do
0N/A setup do
0N/A post :create, :language_id => @source_language.id,
0N/A :language_mapping => {:source_id => @source_language.id,
144N/A :target_id => @target_language.id,
0N/A :iri => "http://test.de"
0N/A }
1105N/A end
0N/A
102N/A should "create the record" do
607N/A mapping = LanguageMapping.find_by_iri("http://test.de")
102N/A assert !mapping.nil?
102N/A assert_equal @source_language, mapping.source unless mapping.nil?
102N/A assert_equal @target_language, mapping.target unless mapping.nil?
102N/A end
102N/A end
102N/A
0N/A context 'on PUT to Update' do
102N/A setup do
102N/A put :update, :language_id => @source_language.id, :id => @mapping.id,
0N/A :language_mapping => {:source_id => @source_language.id,
102N/A :target_id => @target_language.id,
66N/A :iri => "http://test2.de"
}
end
should "change the record" do
mapping = LanguageMapping.find_by_iri("http://test2.de")
assert !mapping.nil?
assert_equal @source_language, mapping.source unless mapping.nil?
assert_equal @target_language, mapping.target unless mapping.nil?
end
end
context "on POST to DELETE" do
setup do
delete :destroy, :id => @mapping.id, :language_id => @source_language.id
end
should "remove the record" do
assert_equal nil, LanguageMapping.find_by_id(@mapping.id)
end
end
context "on GET to EDIT" do
setup do
get :edit, :id => @mapping.id, :language_id => @source_language.id
end
should respond_with :success
should assign_to :language_mapping
should render_template :edit
should_not set_the_flash
end
end
context 'signed in as not-owner' do
setup do
@user2 = FactoryGirl.create :user
sign_in @user2
end
context 'on get to show' do
setup do
get :show, :id => @mapping.id, :language_id => @source_language.id
end
should respond_with :success
should assign_to :language_mapping
should render_template :show
should_not set_the_flash
end
context 'on get to new' do
setup do
get :new, :language_id => @source_language.id
end
should respond_with :success
should render_template :new
end
context 'on POST to CREATE' do
setup do
post :create, :language_id => @source_language.id,
:language_mapping => {:source_id => @source_language.id,
:target_id => @target_language.id,
:iri => "http://test.de"
}
end
should "create the record" do
mapping = LanguageMapping.find_by_iri("http://test.de")
assert !mapping.nil?
assert_equal @source_language, mapping.source unless mapping.nil?
assert_equal @target_language, mapping.target unless mapping.nil?
end
end
context 'on PUT to Update' do
setup do
put :update, :language_id => @source_language.id, :id => @mapping.id,
:language_mapping => {:source_id => @source_language.id,
:target_id => @target_language.id,
:iri => "http://test2.de"
}
end
should "not change the record" do
mapping = LanguageMapping.find_by_iri("http://test2.de")
assert_equal nil, mapping
end
end
context "on POST to DELETE" do
setup do
delete :destroy, :id => @mapping.id, :language_id => @source_language.id
end
should "not remove the record" do
mapping = LanguageMapping.find_by_id(@mapping.id)
assert_equal @mapping, mapping
end
end
context "on GET to EDIT" do
setup do
get :edit, :id => @mapping.id, :language_id => @source_language.id
end
should respond_with :redirect
should set_the_flash.to(/not authorized/i)
end
end
context 'not signed in' do
context 'on get to show' do
setup do
get :show, :id => @mapping.id, :language_id => @source_language.id
end
should respond_with :success
should assign_to :language_mapping
should render_template :show
should_not set_the_flash
end
context 'on get to new' do
setup do
get :new, :language_id => @source_language.id
end
should respond_with :redirect
should set_the_flash
end
end
context 'on POST to CREATE' do
setup do
post :create, :language_id => @source_language.id,
:language_mapping => {:source_id => @source_language.id,
:target_id => @target_language.id,
:iri => "http://test.de"
}
end
should "not create the record" do
mapping = LanguageMapping.find_by_iri("http://test.de")
assert_equal nil, mapping
end
end
context 'on PUT to Update' do
setup do
put :update, :language_id => @source_language.id, :id => @mapping.id,
:language_mapping => {:source_id => @source_language.id,
:target_id => @target_language.id,
:iri => "http://test2.de"
}
end
should "not change the record" do
mapping = LanguageMapping.find_by_iri("http://test2.de")
assert_equal nil, mapping
end
end
context "on POST to DELETE" do
setup do
delete :destroy, :id => @mapping.id, :language_id => @source_language.id
end
should "not remove the record" do
assert_equal @mapping, LanguageMapping.find_by_id(@mapping.id)
end
end
end
end