63 lines
1.9 KiB
Ruby
63 lines
1.9 KiB
Ruby
# root application situation
|
|
class Test1
|
|
end
|
|
module Api
|
|
class Test1sController < ApplicationController
|
|
include Dunlop::Ember::ApiBaseController
|
|
end
|
|
end
|
|
|
|
# namespaced engine situation
|
|
module Adapter1
|
|
class Test2
|
|
end
|
|
module Api
|
|
class Test2sController < ApplicationController
|
|
include Dunlop::Ember::ApiBaseController
|
|
end
|
|
class RootFallBackModelsController < ApplicationController
|
|
include Dunlop::Ember::ApiBaseController
|
|
end
|
|
end
|
|
end
|
|
|
|
class RootFallBackModel
|
|
# Root model, requested by namespaced controller
|
|
end
|
|
|
|
describe Dunlop::Ember::ApiBaseController do
|
|
describe '#record_class private method, but for now because of unit control' do
|
|
it "finds the proper class on Api:: namespace" do
|
|
Api::Test1sController.new.record_class.should eq Test1
|
|
end
|
|
|
|
it "finds the proper class on Adapter::Api:: namespace" do
|
|
Adapter1::Api::Test2sController.new.record_class.should eq Adapter1::Test2
|
|
end
|
|
|
|
it 'falls back to demodularized version if namespaced version is not found' do
|
|
controller = Adapter1::Api::RootFallBackModelsController.new
|
|
controller.record_class.should eq RootFallBackModel
|
|
end
|
|
end
|
|
|
|
describe '#record_params' do
|
|
it "finds the proper class on Api:: namespace" do
|
|
controller = Api::Test1sController.new
|
|
expect(controller).to receive(:params).and_return ActionController::Parameters.new(test1: {a: 1, b: 2})
|
|
expect(controller).to receive(:permitted_params).and_return [:a]
|
|
controller.__send__(:record_params).to_hash.should eq('a' => 1)
|
|
end
|
|
|
|
it "finds the proper class on Adapter::Api:: namespace" do
|
|
controller = Adapter1::Api::Test2sController.new
|
|
expect(controller).to receive(:params).and_return ActionController::Parameters.new('adapter1/test2' => {a: 1, b: 2})
|
|
expect(controller).to receive(:permitted_params).and_return [:b]
|
|
controller.__send__(:record_params).to_hash.should eq('b' => 2)
|
|
end
|
|
|
|
end
|
|
end
|
|
|
|
|