cloudfuji 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +7 -0
- data/.rspec +4 -0
- data/Gemfile +17 -0
- data/README.md +3 -0
- data/Rakefile +36 -0
- data/app/controllers/cloudfuji/data_controller.rb +33 -0
- data/app/controllers/cloudfuji/envs_controller.rb +31 -0
- data/app/controllers/cloudfuji/mail_controller.rb +37 -0
- data/bin/cloudfuji +86 -0
- data/cloudfuji.gemspec +26 -0
- data/config/routes.rb +1 -0
- data/lib/cloudfuji.rb +53 -0
- data/lib/cloudfuji/action_mailer.rb +35 -0
- data/lib/cloudfuji/app.rb +202 -0
- data/lib/cloudfuji/bar.rb +19 -0
- data/lib/cloudfuji/base.rb +23 -0
- data/lib/cloudfuji/command.rb +110 -0
- data/lib/cloudfuji/config.rb +12 -0
- data/lib/cloudfuji/data.rb +52 -0
- data/lib/cloudfuji/data_helper.rb +1 -0
- data/lib/cloudfuji/dns.rb +195 -0
- data/lib/cloudfuji/engine.rb +21 -0
- data/lib/cloudfuji/envs.rb +6 -0
- data/lib/cloudfuji/envs_helper.rb +1 -0
- data/lib/cloudfuji/event.rb +63 -0
- data/lib/cloudfuji/event_observer.rb +20 -0
- data/lib/cloudfuji/mail_helper.rb +1 -0
- data/lib/cloudfuji/mail_route.rb +186 -0
- data/lib/cloudfuji/middleware.rb +42 -0
- data/lib/cloudfuji/models.rb +59 -0
- data/lib/cloudfuji/notification.rb +0 -0
- data/lib/cloudfuji/orm/active_record.rb +44 -0
- data/lib/cloudfuji/orm/mongoid.rb +31 -0
- data/lib/cloudfuji/platform.rb +47 -0
- data/lib/cloudfuji/schema.rb +42 -0
- data/lib/cloudfuji/smtp.rb +24 -0
- data/lib/cloudfuji/user.rb +59 -0
- data/lib/cloudfuji/user_helper.rb +7 -0
- data/lib/cloudfuji/utils.rb +53 -0
- data/lib/cloudfuji/version.rb +4 -0
- data/lib/generators/active_record/cloudfuji_generator.rb +28 -0
- data/lib/generators/active_record/templates/migration.rb +20 -0
- data/lib/generators/cloudfuji/auth_migration_generator.rb +46 -0
- data/lib/generators/cloudfuji/cloudfuji_generator.rb +14 -0
- data/lib/generators/cloudfuji/hooks_generator.rb +43 -0
- data/lib/generators/cloudfuji/install_generator.rb +24 -0
- data/lib/generators/cloudfuji/mail_routes_generator.rb +45 -0
- data/lib/generators/cloudfuji/orm_helpers.rb +21 -0
- data/lib/generators/cloudfuji/routes_generator.rb +22 -0
- data/lib/generators/mongoid/cloudfuji_generator.rb +17 -0
- data/lib/generators/templates/README +5 -0
- data/lib/generators/templates/cloudfuji.rb +10 -0
- data/lib/hooks.rb +36 -0
- data/lib/rails/routes.rb +42 -0
- data/lib/tasks/cloudfuji.rake +6 -0
- data/spec/app_spec/controllers/envs_controller_spec.rb +25 -0
- data/spec/app_spec/controllers/mail_controller_spec.rb +28 -0
- data/spec/app_spec/integration/app_claim_spec.rb +16 -0
- data/spec/gem_spec/base_spec.rb +24 -0
- data/spec/gem_spec/command_spec.rb +181 -0
- data/spec/gem_spec/config_spec.rb +9 -0
- data/spec/gem_spec/data_spec.rb +13 -0
- data/spec/gem_spec/hooks_spec.rb +5 -0
- data/spec/gem_spec/mail_route_spec.rb +168 -0
- data/spec/gem_spec/platform_spec.rb +9 -0
- data/spec/gem_spec/user_spec.rb +45 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/test_apps/rails-2.3/.gitignore +13 -0
- data/spec/test_apps/rails-2.3/Gemfile +13 -0
- data/spec/test_apps/rails-2.3/README +243 -0
- data/spec/test_apps/rails-2.3/Rakefile +10 -0
- data/spec/test_apps/rails-2.3/app/controllers/application_controller.rb +10 -0
- data/spec/test_apps/rails-2.3/app/helpers/application_helper.rb +3 -0
- data/spec/test_apps/rails-2.3/config/boot.rb +114 -0
- data/spec/test_apps/rails-2.3/config/environment.rb +41 -0
- data/spec/test_apps/rails-2.3/config/environments/development.rb +17 -0
- data/spec/test_apps/rails-2.3/config/environments/production.rb +28 -0
- data/spec/test_apps/rails-2.3/config/environments/test.rb +30 -0
- data/spec/test_apps/rails-2.3/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_apps/rails-2.3/config/initializers/cookie_verification_secret.rb +7 -0
- data/spec/test_apps/rails-2.3/config/initializers/inflections.rb +10 -0
- data/spec/test_apps/rails-2.3/config/initializers/mime_types.rb +5 -0
- data/spec/test_apps/rails-2.3/config/initializers/new_rails_defaults.rb +21 -0
- data/spec/test_apps/rails-2.3/config/initializers/session_store.rb +15 -0
- data/spec/test_apps/rails-2.3/config/locales/en.yml +5 -0
- data/spec/test_apps/rails-2.3/config/routes.rb +43 -0
- data/spec/test_apps/rails-2.3/db/seeds.rb +7 -0
- data/spec/test_apps/rails-2.3/doc/README_FOR_APP +2 -0
- data/spec/test_apps/rails-2.3/lib/tasks/rspec.rake +144 -0
- data/spec/test_apps/rails-2.3/public/404.html +30 -0
- data/spec/test_apps/rails-2.3/public/422.html +30 -0
- data/spec/test_apps/rails-2.3/public/500.html +30 -0
- data/spec/test_apps/rails-2.3/public/favicon.ico +0 -0
- data/spec/test_apps/rails-2.3/public/images/rails.png +0 -0
- data/spec/test_apps/rails-2.3/public/javascripts/application.js +2 -0
- data/spec/test_apps/rails-2.3/public/javascripts/controls.js +963 -0
- data/spec/test_apps/rails-2.3/public/javascripts/dragdrop.js +973 -0
- data/spec/test_apps/rails-2.3/public/javascripts/effects.js +1128 -0
- data/spec/test_apps/rails-2.3/public/javascripts/prototype.js +4320 -0
- data/spec/test_apps/rails-2.3/public/robots.txt +5 -0
- data/spec/test_apps/rails-2.3/script/about +4 -0
- data/spec/test_apps/rails-2.3/script/autospec +6 -0
- data/spec/test_apps/rails-2.3/script/console +3 -0
- data/spec/test_apps/rails-2.3/script/dbconsole +3 -0
- data/spec/test_apps/rails-2.3/script/destroy +3 -0
- data/spec/test_apps/rails-2.3/script/generate +3 -0
- data/spec/test_apps/rails-2.3/script/performance/benchmarker +3 -0
- data/spec/test_apps/rails-2.3/script/performance/profiler +3 -0
- data/spec/test_apps/rails-2.3/script/plugin +3 -0
- data/spec/test_apps/rails-2.3/script/runner +3 -0
- data/spec/test_apps/rails-2.3/script/server +3 -0
- data/spec/test_apps/rails-2.3/script/spec +10 -0
- data/spec/test_apps/rails-2.3/spec/all_spec.rb +5 -0
- data/spec/test_apps/rails-2.3/spec/rcov.opts +2 -0
- data/spec/test_apps/rails-2.3/spec/spec.opts +4 -0
- data/spec/test_apps/rails-2.3/spec/spec_helper.rb +83 -0
- data/spec/test_apps/rails-2.3/test/performance/browsing_test.rb +9 -0
- data/spec/test_apps/rails-2.3/test/test_helper.rb +38 -0
- data/spec/test_apps/rails-3.0/.gitignore +4 -0
- data/spec/test_apps/rails-3.0/.rspec +2 -0
- data/spec/test_apps/rails-3.0/Gemfile +10 -0
- data/spec/test_apps/rails-3.0/README +256 -0
- data/spec/test_apps/rails-3.0/Rakefile +7 -0
- data/spec/test_apps/rails-3.0/app/controllers/application_controller.rb +3 -0
- data/spec/test_apps/rails-3.0/app/controllers/static_controller.rb +4 -0
- data/spec/test_apps/rails-3.0/app/helpers/application_helper.rb +2 -0
- data/spec/test_apps/rails-3.0/app/helpers/static_helper.rb +2 -0
- data/spec/test_apps/rails-3.0/app/views/layouts/application.html.erb +14 -0
- data/spec/test_apps/rails-3.0/app/views/static/home.html.erb +1 -0
- data/spec/test_apps/rails-3.0/config.ru +4 -0
- data/spec/test_apps/rails-3.0/config/application.rb +46 -0
- data/spec/test_apps/rails-3.0/config/boot.rb +6 -0
- data/spec/test_apps/rails-3.0/config/environment.rb +5 -0
- data/spec/test_apps/rails-3.0/config/environments/development.rb +26 -0
- data/spec/test_apps/rails-3.0/config/environments/production.rb +49 -0
- data/spec/test_apps/rails-3.0/config/environments/test.rb +35 -0
- data/spec/test_apps/rails-3.0/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_apps/rails-3.0/config/initializers/inflections.rb +10 -0
- data/spec/test_apps/rails-3.0/config/initializers/mime_types.rb +5 -0
- data/spec/test_apps/rails-3.0/config/initializers/secret_token.rb +7 -0
- data/spec/test_apps/rails-3.0/config/initializers/session_store.rb +8 -0
- data/spec/test_apps/rails-3.0/config/locales/en.yml +5 -0
- data/spec/test_apps/rails-3.0/config/routes.rb +62 -0
- data/spec/test_apps/rails-3.0/db/schema.rb +15 -0
- data/spec/test_apps/rails-3.0/db/seeds.rb +7 -0
- data/spec/test_apps/rails-3.0/doc/README_FOR_APP +2 -0
- data/spec/test_apps/rails-3.0/lib/tasks/.gitkeep +0 -0
- data/spec/test_apps/rails-3.0/public/404.html +26 -0
- data/spec/test_apps/rails-3.0/public/422.html +26 -0
- data/spec/test_apps/rails-3.0/public/500.html +26 -0
- data/spec/test_apps/rails-3.0/public/favicon.ico +0 -0
- data/spec/test_apps/rails-3.0/public/images/rails.png +0 -0
- data/spec/test_apps/rails-3.0/public/index.html +239 -0
- data/spec/test_apps/rails-3.0/public/javascripts/application.js +2 -0
- data/spec/test_apps/rails-3.0/public/javascripts/controls.js +965 -0
- data/spec/test_apps/rails-3.0/public/javascripts/dragdrop.js +974 -0
- data/spec/test_apps/rails-3.0/public/javascripts/effects.js +1123 -0
- data/spec/test_apps/rails-3.0/public/javascripts/prototype.js +6001 -0
- data/spec/test_apps/rails-3.0/public/javascripts/rails.js +191 -0
- data/spec/test_apps/rails-3.0/public/robots.txt +5 -0
- data/spec/test_apps/rails-3.0/public/stylesheets/.gitkeep +0 -0
- data/spec/test_apps/rails-3.0/script/rails +6 -0
- data/spec/test_apps/rails-3.0/spec/all_spec.rb +5 -0
- data/spec/test_apps/rails-3.0/spec/spec_helper.rb +78 -0
- data/spec/test_apps/rails-3.0/test/performance/browsing_test.rb +9 -0
- data/spec/test_apps/rails-3.0/test/test_helper.rb +13 -0
- data/spec/test_apps/rails-3.0/vendor/plugins/.gitkeep +0 -0
- data/tasks/cover_me.rake +11 -0
- data/test_app/spec/views/home.html.erb_spec.rb +15 -0
- metadata +261 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Cloudfuji
|
|
2
|
+
module Generators
|
|
3
|
+
module OrmHelpers
|
|
4
|
+
def model_contents
|
|
5
|
+
<<-CONTENT
|
|
6
|
+
# Bind to a shared Cloudfuji model
|
|
7
|
+
cloudfuji :customer_lead
|
|
8
|
+
|
|
9
|
+
CONTENT
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def model_exists?
|
|
13
|
+
File.exists?(File.join(destination_root, model_path))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def model_path
|
|
17
|
+
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Cloudfuji
|
|
2
|
+
module Generators
|
|
3
|
+
class RoutesGenerator < Rails::Generators::Base
|
|
4
|
+
|
|
5
|
+
def create_routes_file
|
|
6
|
+
prepend_to_file("config/routes.rb") do
|
|
7
|
+
<<-EOF
|
|
8
|
+
begin
|
|
9
|
+
Rails.application.routes.draw do
|
|
10
|
+
cloudfuji_routes
|
|
11
|
+
end
|
|
12
|
+
rescue => e
|
|
13
|
+
puts "Error loading the Cloudfuji routes:"
|
|
14
|
+
puts "\#{e.inspect}"
|
|
15
|
+
end
|
|
16
|
+
EOF
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'generators/cloudfuji/orm_helpers'
|
|
2
|
+
|
|
3
|
+
module Mongoid
|
|
4
|
+
module Generators
|
|
5
|
+
class cloudfujiGenerator < Rails::Generators::NamedBase
|
|
6
|
+
include cloudfuji::Generators::OrmHelpers
|
|
7
|
+
|
|
8
|
+
def generate_model
|
|
9
|
+
invoke "mongoid:model", [name] unless model_exists?
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def inject_cloudfuji_content
|
|
13
|
+
inject_into_file model_path, model_contents, :after => "include Mongoid::Document\n"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Cloudfuji.setup do |config|
|
|
2
|
+
#We should abstract this way and intelligently pick the orm
|
|
3
|
+
|
|
4
|
+
# ==> ORM configuration
|
|
5
|
+
# Load and configure the ORM. Supports :active_record (default) and
|
|
6
|
+
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
|
7
|
+
# available as additional gems.
|
|
8
|
+
require 'cloudfuji/orm/<%= options[:orm] %>'
|
|
9
|
+
|
|
10
|
+
end
|
data/lib/hooks.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Hooks
|
|
2
|
+
@@hooks = {}
|
|
3
|
+
|
|
4
|
+
def fire(data, *events)
|
|
5
|
+
#puts "Hooks: #{@@hooks.inspect}"
|
|
6
|
+
#puts "Events: #{events.inspect}"
|
|
7
|
+
#puts "\twith data: #{data.inspect}"
|
|
8
|
+
unless @@hooks[:global].nil?
|
|
9
|
+
@@hooks[:global].call(data, 'global')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
if events.length > 0
|
|
13
|
+
events.each do |event|
|
|
14
|
+
#print "Checking for event: #{event} in hooks..."
|
|
15
|
+
if @@hooks[event].nil?
|
|
16
|
+
#puts "not found, ignoring."
|
|
17
|
+
else
|
|
18
|
+
#puts "found, firing!"
|
|
19
|
+
@@hooks[event].call(data, event)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def listen *events, &block
|
|
26
|
+
#puts "Listening for #{events.inspect}"
|
|
27
|
+
|
|
28
|
+
if events.empty? and block_given?
|
|
29
|
+
@@hooks[:global] = block
|
|
30
|
+
elsif !events.nil? and block_given?
|
|
31
|
+
events.each do |event|
|
|
32
|
+
@@hooks[event] = block
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
data/lib/rails/routes.rb
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
if ActionController::Routing.name =~ /ActionDispatch/
|
|
2
|
+
|
|
3
|
+
# Rails 3.x
|
|
4
|
+
|
|
5
|
+
module ActionDispatch::Routing
|
|
6
|
+
class RouteSet #:nodoc:
|
|
7
|
+
Mapper.class_eval do
|
|
8
|
+
def cloudfuji_routes
|
|
9
|
+
Rails.application.routes.draw do
|
|
10
|
+
namespace 'cloudfuji' do
|
|
11
|
+
resources :envs, :only => [ :update ]
|
|
12
|
+
match '/data' => "data#index"
|
|
13
|
+
|
|
14
|
+
# TODO restrict to POST-only
|
|
15
|
+
match '/mail' => "mail#index"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
else
|
|
24
|
+
|
|
25
|
+
# Rails 2.x
|
|
26
|
+
module ActionController::Routing
|
|
27
|
+
class RouteSet
|
|
28
|
+
|
|
29
|
+
Mapper.class_eval do
|
|
30
|
+
def cloudfuji_routes
|
|
31
|
+
namespace 'cloudfuji' do |cloudfuji|
|
|
32
|
+
cloudfuji.resources :envs, :only => [ :update ]
|
|
33
|
+
cloudfuji.connect '/data', :controller=>:data, :action=>:index
|
|
34
|
+
cloudfuji.connect '/mail', :controller=>:mail, :action=>:index
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Cloudfuji::EnvsController do
|
|
4
|
+
before(:each) do
|
|
5
|
+
ENV["CLOUDFUJI_APP_KEY"] = "abc123"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
context "updating env vars" do
|
|
9
|
+
describe "PUT '/cloudfuji/envs'" do
|
|
10
|
+
it "should return 405 when given the wrong key" do
|
|
11
|
+
preserve_envs("CLOUDFUJI_EXAMPLE", "CLOUDFUJI_APP_KEY", "CLOUDFUJI_ENV") do
|
|
12
|
+
post :update, {:key => "not-the-key", :id => "CLOUDFUJI_EXAMPLE", :value => "value"}
|
|
13
|
+
ENV["CLOUDFUJI_EXAMPLE"].should be_nil
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should update the ENV var when given the right key" do
|
|
18
|
+
preserve_envs("CLOUDFUJI_EXAMPLE", "CLOUDFUJI_APP_KEY", "CLOUDFUJI_ENV") do
|
|
19
|
+
post :update, {:key => ENV["CLOUDFUJI_APP_KEY"].dup, :id => "CLOUDFUJI_EXAMPLE", :value => "value"}
|
|
20
|
+
ENV["CLOUDFUJI_EXAMPLE"].should == "value"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Cloudfuji::MailController do
|
|
4
|
+
|
|
5
|
+
describe "index" do
|
|
6
|
+
before :each do
|
|
7
|
+
# Rspec 1.3 doesn't support any_istance.
|
|
8
|
+
# So we instead stub and object and return that instead
|
|
9
|
+
obj = Object.new
|
|
10
|
+
|
|
11
|
+
Cloudfuji::Mailroute.should_receive(:routes).and_return(obj)
|
|
12
|
+
obj.should_receive(:process)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should return status 200" do
|
|
16
|
+
post 'index'
|
|
17
|
+
|
|
18
|
+
if defined?(Rails) && Rails::VERSION::MAJOR == 2
|
|
19
|
+
response.status.should == "200 OK"
|
|
20
|
+
else
|
|
21
|
+
response.status.should == 200
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'claiming an app' do
|
|
4
|
+
it "marks claimed = false in the markup" do
|
|
5
|
+
visit "/"
|
|
6
|
+
#page.body.include?("var _cloudfuji_claimed = false;").should be_true
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "marks claimed = false in the markup" do
|
|
10
|
+
preserve_envs("CLOUDFUJI_CLAIMED") do
|
|
11
|
+
ENV["CLOUDFUJI_CLAIMED"] = "true"
|
|
12
|
+
visit "/"
|
|
13
|
+
#page.body.include?("var _cloudfuji_claimed = true;").should be_true
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Cloudfuji::Base" do
|
|
4
|
+
|
|
5
|
+
def url_helpers
|
|
6
|
+
{
|
|
7
|
+
:unity=>[:valid, :exists,
|
|
8
|
+
:invite, :pending_invites,
|
|
9
|
+
:remove],
|
|
10
|
+
|
|
11
|
+
:email=>[:send]
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should have url helper methods" do
|
|
16
|
+
url_helpers.stringify_keys.each do |prefix, method_names|
|
|
17
|
+
method_names.each do |method_name|
|
|
18
|
+
full_method_name = method_name.to_s + "_" + prefix + "_" + "url"
|
|
19
|
+
Cloudfuji::Base.send(full_method_name.to_sym).should == "#{Cloudfuji::Platform.host}/#{prefix}/#{Cloudfuji::Config.api_version}/#{method_name}"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Cloudfuji::Command" do
|
|
4
|
+
|
|
5
|
+
before :each do
|
|
6
|
+
@dummy_url = "/sample_api_path"
|
|
7
|
+
@api_params = @sample_result = @rest_params = {:key1=>"value1", :key2=>"value2"}
|
|
8
|
+
@rest_params.merge!({:auth_token => Cloudfuji::Platform.key}) if params[:auth_token].nil? unless Cloudfuji::Platform.key.nil?
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "last_command_successful?" do
|
|
12
|
+
it "should initially return true" do
|
|
13
|
+
Cloudfuji::Command.last_command_successful?.should be_true
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe "last_command_errored?" do
|
|
18
|
+
it "should initially return false" do
|
|
19
|
+
Cloudfuji::Command.last_command_errored?.should be_false
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "request_count" do
|
|
24
|
+
it "should initially be 0" do
|
|
25
|
+
Cloudfuji::Command.request_count == 0
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should return the request count" do
|
|
29
|
+
Cloudfuji::Command.class_eval "@@request_count = 42"
|
|
30
|
+
Cloudfuji::Command.request_count.should == 42
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe "show_response" do
|
|
35
|
+
before :each do
|
|
36
|
+
@response = {:messages => ["value1", "value2"],
|
|
37
|
+
:errors => ["value1", "value2"]}
|
|
38
|
+
end
|
|
39
|
+
it "should show messages" do
|
|
40
|
+
Cloudfuji::Command.should_receive(:show_messages).with(@response)
|
|
41
|
+
Cloudfuji::Command.show_response(@response)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should show errors" do
|
|
45
|
+
Cloudfuji::Command.should_receive(:show_errors).with(@response)
|
|
46
|
+
Cloudfuji::Command.show_errors(@response)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# GET request
|
|
51
|
+
describe "get_command" do
|
|
52
|
+
describe "valids" do
|
|
53
|
+
before :each do
|
|
54
|
+
RestClient.should_receive(:get).
|
|
55
|
+
with(@dummy_url, {:params => @rest_params, :accept => :json}).
|
|
56
|
+
and_return(@sample_result.to_json)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "should increment the request count" do
|
|
60
|
+
expect {
|
|
61
|
+
Cloudfuji::Command.get_command(@dummy_url, @api_params)
|
|
62
|
+
}.to change(Cloudfuji::Command, :request_count).by(1)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "should set last command as successful" do
|
|
66
|
+
Cloudfuji::Command.get_command(@dummy_url, @api_params)
|
|
67
|
+
Cloudfuji::Command.last_command_successful?.should be_true
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should return the request result" do
|
|
71
|
+
# JSON parsing returns stringified keys
|
|
72
|
+
Cloudfuji::Command.get_command(@dummy_url, @api_params).should == @sample_result.stringify_keys
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe "invalids" do
|
|
77
|
+
before :each do
|
|
78
|
+
RestClient.should_receive(:get).
|
|
79
|
+
with(@dummy_url, {:params => @rest_params, :accept => :json}).
|
|
80
|
+
and_throw(:any_exception)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should set last command as failed" do
|
|
84
|
+
Cloudfuji::Command.get_command(@dummy_url, @api_params)
|
|
85
|
+
Cloudfuji::Command.last_command_errored?.should be_true
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "should return nil" do
|
|
89
|
+
Cloudfuji::Command.get_command(@dummy_url, @api_params).should == nil
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# POST request
|
|
95
|
+
describe "post_command" do
|
|
96
|
+
describe "valids" do
|
|
97
|
+
before :each do
|
|
98
|
+
RestClient.should_receive(:post).
|
|
99
|
+
with(@dummy_url, @rest_params.to_json, :content_type => :json, :accept => :json).
|
|
100
|
+
and_return(@sample_result.to_json)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "should increment the request count" do
|
|
104
|
+
expect {
|
|
105
|
+
Cloudfuji::Command.post_command(@dummy_url, @api_params)
|
|
106
|
+
}.to change(Cloudfuji::Command, :request_count).by(1)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "should set last command as successful" do
|
|
110
|
+
Cloudfuji::Command.post_command(@dummy_url, @api_params)
|
|
111
|
+
Cloudfuji::Command.last_command_successful?.should be_true
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "should return the request result" do
|
|
115
|
+
Cloudfuji::Command.post_command(@dummy_url, @api_params).should == @sample_result.stringify_keys
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe "invalids" do
|
|
120
|
+
before :each do
|
|
121
|
+
RestClient.should_receive(:post).
|
|
122
|
+
with(@dummy_url, @rest_params.to_json, :content_type => :json, :accept => :json).
|
|
123
|
+
and_throw(:exception)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "should set last command as failed" do
|
|
127
|
+
Cloudfuji::Command.post_command(@dummy_url, @api_params)
|
|
128
|
+
Cloudfuji::Command.last_command_errored?.should be_true
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it "should return nil" do
|
|
132
|
+
Cloudfuji::Command.post_command(@dummy_url, @api_params).should == nil
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# PUT request
|
|
138
|
+
describe "put_command" do
|
|
139
|
+
describe "valids" do
|
|
140
|
+
before :each do
|
|
141
|
+
RestClient.should_receive(:put).
|
|
142
|
+
with(@dummy_url, @rest_params.to_json, :content_type => :json).
|
|
143
|
+
and_return(@sample_result.to_json)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it "should increment the request count" do
|
|
147
|
+
expect {
|
|
148
|
+
Cloudfuji::Command.put_command(@dummy_url, @api_params)
|
|
149
|
+
}.to change(Cloudfuji::Command, :request_count).by(1)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it "should set last command as successful" do
|
|
153
|
+
Cloudfuji::Command.put_command(@dummy_url, @api_params)
|
|
154
|
+
Cloudfuji::Command.last_command_successful?.should be_true
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
it "should return the request result" do
|
|
158
|
+
Cloudfuji::Command.put_command(@dummy_url, @api_params).should == @sample_result.stringify_keys
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
describe "invalids" do
|
|
163
|
+
before :each do
|
|
164
|
+
RestClient.should_receive(:put).
|
|
165
|
+
with(@dummy_url, @rest_params.to_json, :content_type => :json).
|
|
166
|
+
and_throw(:exception)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it "should set last command as failed" do
|
|
170
|
+
Cloudfuji::Command.put_command(@dummy_url, @api_params)
|
|
171
|
+
Cloudfuji::Command.last_command_errored?.should be_true
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it "should return nil" do
|
|
175
|
+
Cloudfuji::Command.put_command(@dummy_url, @api_params).should == nil
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
end
|