diff --git a/Gemfile b/Gemfile index 104300a..d8aa8a7 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/app/controllers/washout_builder/washout_builder_controller.rb b/app/controllers/washout_builder/washout_builder_controller.rb index 7155fb6..4de3db2 100644 --- a/app/controllers/washout_builder/washout_builder_controller.rb +++ b/app/controllers/washout_builder/washout_builder_controller.rb @@ -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 diff --git a/lib/washout_builder/version.rb b/lib/washout_builder/version.rb index 983b5f4..fb32832 100644 --- a/lib/washout_builder/version.rb +++ b/lib/washout_builder/version.rb @@ -1,3 +1,3 @@ module WashoutBuilder - VERSION = "0.13.5" + VERSION = "0.13.6" end diff --git a/spec/app/controllers/washout_builder_controller_spec.rb b/spec/app/controllers/washout_builder_controller_spec.rb index c511ff4..060be7b 100644 --- a/spec/app/controllers/washout_builder_controller_spec.rb +++ b/spec/app/controllers/washout_builder_controller_spec.rb @@ -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) @@ -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) diff --git a/spec/lib/washout_builder/document/complex_type_spec.rb b/spec/lib/washout_builder/document/complex_type_spec.rb index aa2a20b..1935070 100644 --- a/spec/lib/washout_builder/document/complex_type_spec.rb +++ b/spec/lib/washout_builder/document/complex_type_spec.rb @@ -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) } diff --git a/spec/lib/washout_builder/document/exception_model_spec.rb b/spec/lib/washout_builder/document/exception_model_spec.rb index e40101c..6e81c51 100644 --- a/spec/lib/washout_builder/document/exception_model_spec.rb +++ b/spec/lib/washout_builder/document/exception_model_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/lib/washout_builder/document/generator_spec.rb b/spec/lib/washout_builder/document/generator_spec.rb index 8294d2f..2a16463 100644 --- a/spec/lib/washout_builder/document/generator_spec.rb +++ b/spec/lib/washout_builder/document/generator_spec.rb @@ -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 @@ -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") @@ -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) } @@ -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 @@ -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 diff --git a/spec/lib/washout_builder/type_spec.rb b/spec/lib/washout_builder/type_spec.rb index 143faac..0f2d71a 100644 --- a/spec/lib/washout_builder/type_spec.rb +++ b/spec/lib/washout_builder/type_spec.rb @@ -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 @@ -21,12 +21,12 @@ 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 @@ -34,7 +34,6 @@ 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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 78856d7..408da82 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,6 +3,7 @@ require 'codeclimate-test-reporter' require 'simplecov' +require 'simplecov-summary' require 'coveralls' formatters = [SimpleCov::Formatter::HTMLFormatter] @@ -25,20 +26,18 @@ require 'active_support' require 'nori' require 'nokogiri' +require 'ostruct' require File.expand_path("../dummy/config/environment.rb", __FILE__) require File.expand_path("../../config/routes.rb", __FILE__) require "rails/test_help" require "rspec/rails" require 'rspec/autorun' -require "pry" require "savon" require 'wash_out' require 'capybara/rspec' require 'capybara/rails' -require 'capybara/firebug/rspec' -require 'webmock/rspec' require 'headless' Rails.backtrace_cleaner.remove_silencers! @@ -49,16 +48,15 @@ RSpec.configure do |config| require 'rspec/expectations' config.include RSpec::Matchers - + config.infer_spec_type_from_file_location! config.before(:suite) do # Blocks all remote HTTP requests by default, they need to be stubbed. - WebMock.disable_net_connect!(:allow_localhost => true, :allow => "codeclimate.com") if !RUBY_PLATFORM.downcase.include?('darwin') && !ENV['NO_HEADLESS'] Headless.new(reuse: false, destroy_on_exit: false).start end end - + config.mock_with :mocha config.before(:all) do WashoutBuilder::Engine.config.wash_out = { @@ -100,3 +98,17 @@ def mock_controller(options = {}, &block) ActiveSupport::Dependencies::Reference.instance_variable_get(:'@store').delete('ApiController') end + +def base_exception + WashOut::Dispatcher::SOAPError +end + + +class WashoutBuilderTestError < base_exception + + +end + +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 \ No newline at end of file diff --git a/spec/support/complex_types/project_type.rb b/spec/support/complex_types/project_type.rb index 32ecd88..4562f2f 100644 --- a/spec/support/complex_types/project_type.rb +++ b/spec/support/complex_types/project_type.rb @@ -3,7 +3,6 @@ class ProjectType < WashOut::Type :name => :string, :description => :string, :users => [{:mail => :string }], - # 'dada' => [Project] } end diff --git a/washout_builder.gemspec b/washout_builder.gemspec index 64dbdc8..fb8b5a3 100644 --- a/washout_builder.gemspec +++ b/washout_builder.gemspec @@ -15,5 +15,25 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split("\n") s.test_files = s.files.grep(/^(spec)/) s.require_paths = ["lib"] - s.add_runtime_dependency 'wash_out', '~> 0.9', '>= 0.9.1' + s.add_runtime_dependency 'wash_out', '~> 0.9.1', '>= 0.9.1' + + s.add_development_dependency 'wasabi', '~> 3.3.0', '>= 3.3.0' + s.add_development_dependency 'savon', '~> 2.5.1', '>= 2.5.1' + s.add_development_dependency 'httpi', '~> 2.1.0', '>= 2.1.0' + s.add_development_dependency 'nokogiri', '~> 1.6.0', '>= 1.6.0' + + s.add_development_dependency 'rspec-rails', '~> 2.0', '>= 2.0' + s.add_development_dependency 'guard', '~> 2.6.1', '>= 2.6.1' + s.add_development_dependency 'guard-rspec', '~> 4.2.9', '>= 4.2.9' + s.add_development_dependency 'appraisal', '~> 1.0.0', '>= 1.0.0' + s.add_development_dependency 'simplecov', '>= 0.8.2' + s.add_development_dependency 'simplecov-summary', '>= 0.0.4' + s.add_development_dependency 'mocha','~> 1.1.0', '>= 1.1.0' + s.add_development_dependency 'coveralls','~> 0.7.0', '>= 0.7.0' + s.add_development_dependency 'codeclimate-test-reporter','~> 0.3.0', '>= 0.3.0' + s.add_development_dependency 'rvm-tester','~> 1.1.0', '>= 1.1.0' + + s.add_development_dependency 'capybara', '~> 2.2.1', '>= 2.2.1' + s.add_development_dependency 'selenium-webdriver', '~> 2.41.0', '>= 2.41.0' + s.add_development_dependency 'headless','~> 1.0.1', '>= 1.0.1' end