require 'rack/test' require File.join(File.dirname(__FILE__),'..','spec_helper') require File.join(File.dirname(__FILE__),'..','..','lib','rhoconnect','server.rb') describe "Rhoconnect::Controller::JsBase" do include Rack::Test::Methods include Rhoconnect it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => true do before(:each) do Rhoconnect::Server.set :environment, :test Rhoconnect::Server.set :secret, "secure!" Rhoconnect.use_node = true Rhoconnect.bootstrap(get_testapp_path) do_post "/rc/#{Rhoconnect::API_VERSION}/app/login", "login" => @u.login, "password" => 'testpass' end def app @app ||= Rack::URLMap.new Rhoconnect.url_map end after(:each) do Rhoconnect::Node.kill_process end it "should get / of js controller with route overridden" do get '/app/v1/JsSample', {}, {Rhoconnect::CLIENT_ID_HEADER => @c.id} last_response.should be_ok body = JSON.parse(last_response.body) body[2]['count'].should == 1 body.last['insert'].should == {'1' => {'name' => 'iPhone'}} end it "should get /custom_route of js controller" do get '/app/v1/JsSample/custom_route', {}, {Rhoconnect::CLIENT_ID_HEADER => @c.id} last_response.body.should == 'testuser' end it "should get /source from custom route" do get '/app/v1/JsSample/custom_route2', {}, {Rhoconnect::CLIENT_ID_HEADER => @c.id} last_response.body.should == 'JsSample' end it "should get stash_result from js model" do pending "stash_result not supported yet" get '/app/v1/JsSample/custom_route3',{}, {Rhoconnect::CLIENT_ID_HEADER => @c.id} res = JSON.parse(last_response.body) res[2]["count"].should == 1 end it "should register sync route" do get '/app/v1/Sample2', {}, {Rhoconnect::CLIENT_ID_HEADER => @c.id} res = JSON.parse(last_response.body) res[2]["count"].should == 1 end it "should post to js controller" do hsh = {'1'=>{'name'=>'testname','price'=>'$199'}} post '/app/v1/JsSample',hsh, {Rhoconnect::CLIENT_ID_HEADER => @c.id} last_response.should be_ok end it "should put to js controller" do put '/app/v1/JsSample/2', {}, {Rhoconnect::CLIENT_ID_HEADER => @c.id} last_response.body.should == '' end it "should delete to js controller" do @c1 = Client.create({:user_id => @u.id,:app_id => @a.id},{:source_name => 'JsSample'}) set_doc_state(@c1, :cd => @data) delete '/app/v1/JsSample/2', {}, {Rhoconnect::CLIENT_ID_HEADER => @c1.id} last_response.should be_ok end it "should register deprecated_route" it "should call js model name explicitly" do js = JsSample.new("JsSample") res = js.login res.should == "success" end it "should print warning if model function not found" do js = JsSample.new("JsSample") res = js.foo res.should == "foo method not defined for JsSample" end end end