Skip to content

Commit

Permalink
Merge branch 'release/0.13.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanRada committed Jun 5, 2014
2 parents d562a9c + 074f8e2 commit 5cb0206
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 90 deletions.
30 changes: 0 additions & 30 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,4 @@ gemspec


gem 'wash_out', git: 'git://github.com/inossidabile/wash_out.git'
gem 'wasabi'
gem 'savon'
gem 'httpi'

gem 'rspec-rails'
gem 'guard'
gem 'guard-rspec'
gem 'rb-fsevent'
gem 'appraisal'
gem 'tzinfo'
gem 'pry'
gem 'simplecov'
gem 'simplecov-summary'

gem 'nori'
gem 'nokogiri'

gem 'capybara'
gem 'selenium-webdriver'
gem 'headless'
gem 'capybara-firebug'
gem 'mocha', ">=1.1.0", :require => false
#gem "mocha", "~> 0.12.8", :require => false
gem 'webmock'
gem 'coveralls', require: false
gem "codeclimate-test-reporter", group: :test, require: nil

unless ENV["TRAVIS"]
gem 'rvm-tester'
end

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def map_controllers

def controller_is_a_service?(controller)
route = all_controllers.detect do |route|
route.defaults[:controller].try(:camelize) == controller.camelize && route.defaults[:action] == "_generate_wsdl"
route.defaults[:controller].camelize == controller.camelize && route.defaults[:action] == "_generate_wsdl"
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/washout_builder/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module WashoutBuilder
VERSION = "0.13.5"
VERSION = "0.13.6"
end
6 changes: 5 additions & 1 deletion spec/app/controllers/washout_builder_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def dispatcher_method

let(:washout_builder) { stub(:root_url => "#{request.protocol}#{request.host_with_port}/")}
let(:route) {stub(:defaults => {:controller => "api"})}
let(:params) {{:name => "some_name" }}
let(:params) {{:name => "some_name" }}

before(:each) do
ApiController.stubs(:soap_config).returns(soap_config)
Expand All @@ -33,6 +33,10 @@ def dispatcher_method
response.should render_template("wash_with_html/all_services")
end


it "checks it controller is a service" do
controller.send(:controller_is_a_service?,"api").should_not eq nil
end

it "render a service documentation" do
controller.expects(:controller_is_a_service?).with(params[:name]).returns(route)
Expand Down
6 changes: 1 addition & 5 deletions spec/lib/washout_builder/document/complex_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
namespace: "/api/wsdl",
description: "some description"
) }

def get_wash_out_param(class_name_or_structure, soap_config = soap_config)
WashOut::Param.parse_builder_def(soap_config, class_name_or_structure)[0]
end


let(:subject) { get_wash_out_param(ProjectType) }
let(:namespaced_object) { get_wash_out_param(Api::TestType) }

Expand Down
66 changes: 50 additions & 16 deletions spec/lib/washout_builder/document/exception_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,67 @@

describe WashoutBuilder::Document::ExceptionModel do

let(:subject) { WashOut::Dispatcher::SOAPError}
let(:subject) { WashoutBuilderTestError}

let(:structure) { {"message"=>{:primitive=>"string", :member_type=>nil}, "backtrace"=>{:primitive=>"string", :member_type=>nil}}}
let(:base_structure) { {"code"=>{:primitive=>"integer", :member_type=>nil}, "message"=>{:primitive=>"string", :member_type=>nil}, "backtrace"=>{:primitive=>"string", :member_type=>nil}}}
let(:ancestors) {[base_exception]}

def fault_ancestor_hash(subject, structure, ancestors)
{:fault => subject,:structure =>structure ,:ancestors => ancestors }
end

it "gets the strcuture" do
subject.get_fault_model_structure.should eq({"code"=>{:primitive=>"integer", :member_type=>nil}, "message"=>{:primitive=>"string", :member_type=>nil}, "backtrace"=>{:primitive=>"string", :member_type=>nil}})
subject.get_fault_model_structure.should eq(structure)
end

it "gets the strcuture" do
subject.get_fault_attributes.should eq(["code","message", "backtrace"])
it "gets the strcuture" do
base_exception.get_fault_model_structure.should eq(base_structure)
end
it "gets the strcuture" do
subject.get_fault_attributes.should eq(["message", "backtrace"])
end
it "gets the strcuture" do
base_exception.get_fault_attributes.should eq(["code","message", "backtrace"])
end
#
# it "gets the member type for arrays" do
# subject.get_virtus_member_type_primitive({:primitive=>"Array", :member_type=>"SomeInexistentClass"}).should eq("SomeInexistentClass")
# end
#
# it "gets the member type for clasified types" do
# subject.get_virtus_member_type_primitive({:primitive=>"SomeInexistentClass", :member_type=>nil}).should eq("SomeInexistentClass")
# end
#
# it "returns nil because is not a classified object" do
# subject.get_virtus_member_type_primitive({:primitive=>"integer", :member_type=>nil}).should eq(nil)
# end

specify { subject.check_valid_fault_method?("code").should eq(true) }
specify { subject.get_fault_type_method("code").should eq("integer") }
specify { subject.get_fault_type_method("message").should eq("string") }
specify { subject.get_fault_type_method("backtrace").should eq("string") }

it "gets the strcuture" do
subject.remove_fault_type_inheritable_elements(["code"]).should eq({ "message"=>{:primitive=>"string", :member_type=>nil}, "backtrace"=>{:primitive=>"string", :member_type=>nil}})
end

it "fault_ancestor_hash" do
subject.fault_ancestor_hash( structure, ancestors).should eq(fault_ancestor_hash(subject, structure, ancestors))
end

it "gets the fault_ancestors" do
subject.expects(:get_complex_type_ancestors).with(subject, ["ActiveRecord::Base", "Object", "BasicObject", "Exception" ]).returns(ancestors)
subject.fault_ancestors.should eq ancestors
end

it "gets the fault_without_inheritable_elements" do
ancestors[0].expects(:get_fault_model_structure).returns(structure)
subject.expects(:remove_fault_type_inheritable_elements).with(structure.keys)
subject.fault_without_inheritable_elements(ancestors)
end

it "gets the ancestors" do
subject.expects(:fault_ancestors).returns(nil)
subject.expects(:get_fault_model_structure).returns(structure)
subject.expects(:fault_ancestor_hash).with(structure, []).returns(fault_ancestor_hash(subject, structure, ancestors))
subject.get_fault_class_ancestors([]).should eq(nil)
end

it "gets the ancestors" do
expected_defined = fault_ancestor_hash(subject, structure, ancestors)
subject.expects(:fault_ancestors).returns(ancestors)
subject.expects(:fault_without_inheritable_elements).with(ancestors).returns(structure)
subject.expects(:fault_ancestor_hash).returns(expected_defined)
subject.get_fault_class_ancestors([])
end

end
91 changes: 67 additions & 24 deletions spec/lib/washout_builder/document/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
soap_service namespace: "/api/wsdl", description: "some description"

soap_action 'dispatcher_method', :args => nil, :return => nil

soap_action 'dispatcher_method2', :args => nil, :return => nil, :raises => WashoutBuilderTestError
soap_action 'dispatcher_method3', :args => ProjectType , :return => nil, :raises => [WashoutBuilderTestError]
def dispatcher_method
#nothing
end
def dispatcher_method2
#nothing
end
def dispatcher_method3
#nothing
end
end

describe WashoutBuilder::Document::Generator do
Expand All @@ -17,12 +24,7 @@ def dispatcher_method
namespace: "/api/wsdl",
description: "some description"
) }

let(:soap_actions) {
{'dispatcher_method' =>
{:args => nil, :return => nil, :in => [], :out => [], :builder_in => [], :builder_out => [], :to => 'dispatcher_method'}
}
}

let(:service_class) { ApiController }
before(:each) do
@document = WashoutBuilder::Document::Generator.new("api")
Expand All @@ -49,40 +51,55 @@ def dispatcher_method
end

context "operations" do
specify { @document.operations.should eq(soap_actions.map { |operation, formats| operation }) }
specify { @document.operations.should eq(service_class.soap_actions.map { |operation, formats| operation }) }
end

context "sorted_operations" do

it "returns sorted operations" do
expected = service_class.soap_actions.sort_by { |operation, formats| operation.downcase }.uniq
@document.sorted_operations.should eq expected
end

end

context "input types" do
let(:expected) { types = []
soap_actions.each do |operation, formats|
(formats[:builder_in]).each do |p|
def argument_types(type)
format_type = (type == "input") ? "builder_in" : "builder_out"
types = []
unless service_class.soap_actions.blank?
service_class.soap_actions.each do |operation, formats|
(formats[format_type.to_sym]).each do |p|
types << p
end
end
types }
end
types
end


context "input types" do

specify { @document.input_types.should eq(expected) }
specify { @document.input_types.should eq(argument_types("input")) }

end

context "output types" do
let(:expected) { types = []
soap_actions.each do |operation, formats|
(formats[:builder_out]).each do |p|
types << p
end
end
types }

specify { @document.output_types.should eq(expected) }

specify { @document.output_types.should eq(argument_types("output")) }

end


context "operation exceptions" do

specify { @document.operation_exceptions("dispatcher_method").should eq([]) }
specify { @document.operation_exceptions("dispatcher_method2").should eq([WashoutBuilderTestError]) }
specify { @document.operation_exceptions("dispatcher_method3").should eq([WashoutBuilderTestError]) }
end

context "get_soap_action_names" do

let(:expected) {soap_actions.map { |operation, formats| operation }.map(&:to_s).sort_by { |name| name.downcase }.uniq}
let(:expected) {service_class.soap_actions.map { |operation, formats| operation }.map(&:to_s).sort_by { |name| name.downcase }.uniq}

specify { @document.get_soap_action_names.should eq(expected) }

Expand All @@ -95,6 +112,30 @@ def dispatcher_method
end


context "actions with exceptions" do
let(:actions_with_exceptions) {service_class.soap_actions.select{|operation, formats| !formats[:raises].blank? } }
let(:exceptions_raised) { actions_with_exceptions.collect {|operation, formats| formats[:raises].is_a?(Array) ? formats[:raises] : [formats[:raises]] }.flatten}
let(:filter_exceptions_raised) { exceptions_raised.select { |x| WashoutBuilder::Type.valid_fault_class?(x) } unless actions_with_exceptions.blank?}

specify { @document.actions_with_exceptions.should eq actions_with_exceptions }
specify { @document.exceptions_raised.should eq exceptions_raised }
specify { @document.filter_exceptions_raised.should eq filter_exceptions_raised }

it "returns the fault types" do
WashoutBuilder::Type.stubs(:get_fault_classes).returns([base_exception])
@document.expects(:get_complex_fault_types).with([base_exception]).returns([base_exception])
@document.expects(:sort_complex_types).with([base_exception], "fault").returns([base_exception])
@document.fault_types.should eq([base_exception])
end

it "returns complex fault types" do
base_exception.expects(:get_fault_class_ancestors).with([], true).returns(nil)
@document.expects(:filter_exceptions_raised).returns(nil)
@document.get_complex_fault_types([base_exception]).should eq([])
end

end


context "complex types" do

Expand All @@ -109,6 +150,8 @@ def dispatcher_method
end

it "returns nil if no complex types detected" do
WashOut::Param.any_instance.expects(:get_nested_complex_types).returns([])
@document.expects(:sort_complex_types).with([], "class").returns(nil)
@document.complex_types.should eq(nil)
end

Expand Down
7 changes: 3 additions & 4 deletions spec/lib/washout_builder/type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe WashoutBuilder::Type do

let(:exception) { WashOut::Dispatcher::SOAPError}
let(:exception) { WashoutBuilderTestError}
let(:fault_classes) { [exception] }

it "defines a list of types" do
Expand All @@ -21,20 +21,19 @@
end

it "gets the fault classes defined" do
WashoutBuilder::Type.get_fault_classes.should eq fault_classes
WashoutBuilder::Type.get_fault_classes.should eq ([base_exception])
end

context "exception" do
before(:each) do
WashoutBuilder::Type.stubs(:get_fault_classes).returns(fault_classes)
WashoutBuilder::Type.stubs(:get_fault_classes).returns([base_exception])
end

it "checks if exception has ancestor" do
WashoutBuilder::Type.has_ancestor_fault?(exception).should eq(true)
end

it "checks if exception valid" do
WashoutBuilder::Type.stubs(:has_ancestor_fault?).returns(true)
WashoutBuilder::Type.valid_fault_class?(exception).should eq(true)
end
end
Expand Down
Loading

0 comments on commit 5cb0206

Please sign in to comment.