diff --git a/Rakefile b/Rakefile index 18d3e54..57f5324 100644 --- a/Rakefile +++ b/Rakefile @@ -7,8 +7,20 @@ RSpec::Core::RakeTask.new(:spec) do |spec| # spec.rspec_opts = ['--backtrace '] end +#desc "Prepare dummy application" +#task :prepare do +# ENV["RAILS_ENV"] ||= 'test' +# +# require File.expand_path("./spec/dummy/config/environment", File.dirname(__FILE__)) +# Dummy::Application.load_tasks +# +# Rake::Task["db:test:prepare"].invoke +#end + + + desc "Default: run the unit tests." -task :default => [:all] +task :default => [ :all] desc 'Test the plugin under all supported Rails versions.' task :all => ["appraisal:install"] do |t| diff --git a/lib/washout_builder/document/complex_type.rb b/lib/washout_builder/document/complex_type.rb index 7d95ebf..b1a423d 100644 --- a/lib/washout_builder/document/complex_type.rb +++ b/lib/washout_builder/document/complex_type.rb @@ -37,7 +37,7 @@ def remove_type_inheritable_elements( keys) def fix_descendant_wash_out_type(config, complex_class) param_class = complex_class.is_a?(Class) ? complex_class : complex_class.constantize rescue nil if !param_class.nil? && param_class.ancestors.include?(WashOut::Type) && !map[0].nil? - descendant = WashOut::Param.parse_def(config, param_class.wash_out_param_map)[0] + descendant = WashOut::Param.parse_builder_def(config, param_class.wash_out_param_map)[0] self.name = descendant.name self.map = descendant.map end diff --git a/lib/washout_builder/version.rb b/lib/washout_builder/version.rb index adc5fdd..8aeb66b 100644 --- a/lib/washout_builder/version.rb +++ b/lib/washout_builder/version.rb @@ -1,3 +1,3 @@ module WashoutBuilder - VERSION = "0.11.1" + VERSION = "0.11.2" end diff --git a/spec/app/controllers/washout_builder_controller_spec.rb b/spec/app/controllers/washout_builder_controller_spec.rb index f3cecb9..bfd8a66 100644 --- a/spec/app/controllers/washout_builder_controller_spec.rb +++ b/spec/app/controllers/washout_builder_controller_spec.rb @@ -1,8 +1,27 @@ require 'spec_helper' -describe WashoutBuilderController do + +describe WashoutBuilderController, :type => :controller do + + let(:soap_config) { OpenStruct.new( + camelize_wsdl: false, + namespace: "/api/wsdl", + ) } + before(:each) do + ApiController.stubs(:soap_config).returns(soap_config) + end + + it "gets the services" do + get :all + assigns(:services).should eq([{"service_name"=>"Api", "namespace"=>"/api/wsdl", "endpoint"=>"/api/action", "documentation_url"=>"http://test.host/api/doc"}]) + end + it "renders the template" do + get :all + response.should render_template("wash_with_html/all_services") + end + end \ No newline at end of file diff --git a/spec/lib/washout_builder/document/complex_type_spec.rb b/spec/lib/washout_builder/document/complex_type_spec.rb index e69de29..aa2a20b 100644 --- a/spec/lib/washout_builder/document/complex_type_spec.rb +++ b/spec/lib/washout_builder/document/complex_type_spec.rb @@ -0,0 +1,61 @@ +#encoding:utf-8 +require 'spec_helper' + + +describe WashoutBuilder::Document::ComplexType do + let(:soap_config) { OpenStruct.new( + camelize_wsdl: false, + 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) } + + it "returns the complex class name" do + subject.get_complex_class_name.should eq("ProjectType") + end + + + it "returns the complex class name" do + subject.get_complex_class_name.should eq("ProjectType") + end + + + it "returns the complex class with namespace" do + namespaced_object.get_complex_class_name.should eq("Api::TestType") + end + + + it "returns error if classname already detected (only used for hashes)" do + subject.stubs(:classified?).returns(false) + subject.stubs(:basic_type).returns("ProjectType") + defined = [ { :class= => "ProjectType" }] + defined.stubs(:detect).returns({:class => "ProjectType"}) + expect {subject.get_complex_class_name(defined) }.to raise_error(RuntimeError, "Duplicate use of `ProjectType` type name. Consider using classified types.") + end + + it "returns the param structure" do + subject.get_param_structure.should eq({"project"=>"struct"}) + end + + it "fixes the first descendant " do + descendant = get_wash_out_param(ProjectType.wash_out_param_map) + subject.fix_descendant_wash_out_type(soap_config, ProjectType) + subject.name.should eq(descendant.name) + subject.map[0].get_param_structure.should eq(descendant.map[0].get_param_structure) + end + + it "same as ancestor" do + subject.get_ancestors(ProjectType).should eq([]) + end + + + + + +end \ No newline at end of file diff --git a/spec/lib/washout_builder/document/virtus_model_spec.rb b/spec/lib/washout_builder/document/virtus_model_spec.rb index e69de29..0ac68a4 100644 --- a/spec/lib/washout_builder/document/virtus_model_spec.rb +++ b/spec/lib/washout_builder/document/virtus_model_spec.rb @@ -0,0 +1,35 @@ +#encoding:utf-8 +require 'spec_helper' + +class SOAPError < WashOut::Dispatcher::SOAPError + +end + +describe WashoutBuilder::Document::VirtusModel do + + let(:subject) { SOAPError} + + + + it "gets the strcuture" do + subject.get_virtus_model_structure.should eq({"code"=>{:primitive=>"Integer", :member_type=>nil}, "message"=>{:primitive=>"String", :member_type=>nil}, "backtrace"=>{:primitive=>"String", :member_type=>nil}}) + 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 + + + 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 + +end \ No newline at end of file