Commit bd44aeb1 authored by John E. Vincent's avatar John E. Vincent

cleanup. specs finished. gemtest

parent 03757a64
...@@ -10,3 +10,4 @@ tmp/* ...@@ -10,3 +10,4 @@ tmp/*
*.war *.war
.bundle .bundle
warbler/* warbler/*
Gemfile.lock
...@@ -7,19 +7,18 @@ PATH ...@@ -7,19 +7,18 @@ PATH
ohm (= 0.1.3) ohm (= 0.1.3)
ohm-contrib (= 0.1.1) ohm-contrib (= 0.1.1)
rack (= 1.2.1) rack (= 1.2.1)
rake (= 0.8.7)
redis (= 2.1.1) redis (= 2.1.1)
sinatra (= 1.1.2) sinatra (= 1.1.2)
sinatra-namespace (= 0.6.1) sinatra-namespace (= 0.6.1)
thin (= 1.2.7) thin
tilt (= 1.2.1) tilt (= 1.2.2)
vegas (= 0.1.8) vegas (= 0.1.8)
yajl-ruby (= 0.7.9) yajl-ruby
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
ZenTest (4.4.2) ZenTest (4.5.0)
autotest (4.4.6) autotest (4.4.6)
ZenTest (>= 4.4.1) ZenTest (>= 4.4.1)
autotest-growl (0.2.9) autotest-growl (0.2.9)
...@@ -39,18 +38,16 @@ GEM ...@@ -39,18 +38,16 @@ GEM
rack (1.2.1) rack (1.2.1)
rack-test (0.5.7) rack-test (0.5.7)
rack (>= 1.0) rack (>= 1.0)
rake (0.8.7)
rcov (0.9.9) rcov (0.9.9)
rcov (0.9.9-java)
redis (2.1.1) redis (2.1.1)
rspec (2.4.0) rspec (2.5.0)
rspec-core (~> 2.4.0) rspec-core (~> 2.5.0)
rspec-expectations (~> 2.4.0) rspec-expectations (~> 2.5.0)
rspec-mocks (~> 2.4.0) rspec-mocks (~> 2.5.0)
rspec-core (2.4.0) rspec-core (2.5.1)
rspec-expectations (2.4.0) rspec-expectations (2.5.0)
diff-lcs (~> 1.1.2) diff-lcs (~> 1.1.2)
rspec-mocks (2.4.0) rspec-mocks (2.5.0)
sinatra (1.1.2) sinatra (1.1.2)
rack (~> 1.1) rack (~> 1.1)
tilt (~> 1.2) tilt (~> 1.2)
...@@ -70,21 +67,20 @@ GEM ...@@ -70,21 +67,20 @@ GEM
daemons (>= 1.0.9) daemons (>= 1.0.9)
eventmachine (>= 0.12.6) eventmachine (>= 0.12.6)
rack (>= 1.0.0) rack (>= 1.0.0)
tilt (1.2.1) tilt (1.2.2)
vegas (0.1.8) vegas (0.1.8)
rack (>= 1.0.0) rack (>= 1.0.0)
yajl-ruby (0.7.9) yajl-ruby (0.8.1)
PLATFORMS PLATFORMS
java
ruby ruby
DEPENDENCIES DEPENDENCIES
ZenTest (= 4.4.2) ZenTest (= 4.5.0)
autotest (= 4.4.6) autotest (= 4.4.6)
autotest-growl (= 0.2.9) autotest-growl (= 0.2.9)
noah! noah!
rack-test (= 0.5.7) rack-test (= 0.5.7)
rcov (= 0.9.9) rcov (= 0.9.9)
rspec (= 2.4.0) rspec (~> 2.5)
sinatra-reloader (= 0.5.0) sinatra-reloader (= 0.5.0)
require 'bundler' require 'bundler'
#begin
# Bundler.setup(:default, :development)
#rescue Bundler::BundlerError => e
# $stderr.puts e.message
# $stderr.puts "Run `bundle install` to install missing gems"
# exit e.status_code
#end
require 'rake'
require 'rspec/core' require 'rspec/core'
require 'rspec/core/rake_task' require 'rspec/core/rake_task'
task :default => [:spec]
task :test => [:spec]
Bundler::GemHelper.install_tasks Bundler::GemHelper.install_tasks
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end
namespace :coverage do
desc "Delete aggregate coverage data."
task(:clean) { rm_f "coverage.data" }
end
desc "Run Rcov code coverage analysis"
RSpec::Core::RakeTask.new(:coverage) do |t|
t.rcov = true
t.verbose = true
t.rcov_opts = %q[--aggregate coverage.data --sort coverage --text-report --exclude "config,.bundle/*,gems/*,spec/*" -o doc/coverage -Ilib -i "noah.rb"]
end
desc "Populate database with sample dataset" desc "Populate database with sample dataset"
task :sample, :redis_url do |t, args| task :sample, :redis_url do |t, args|
require 'ohm' require 'ohm'
begin require 'json'
require 'yajl'
rescue LoadError
require 'json'
end
require File.join(File.dirname(__FILE__), 'lib','noah') require File.join(File.dirname(__FILE__), 'lib','noah')
Ohm::connect(:url => args.redis_url) Ohm::connect(:url => args.redis_url)
Ohm::redis.flushdb Ohm::redis.flushdb
puts "Creating Host entry for 'localhost'" puts "Creating Host entry for 'localhost'"
...@@ -88,47 +91,7 @@ EOJ ...@@ -88,47 +91,7 @@ EOJ
puts "Sample data populated!" puts "Sample data populated!"
end end
desc "Demo environment"
RSpec::Core::RakeTask.new(:spec) do |spec| task :start_demo do
spec.pattern = FileList['spec/**/*_spec.rb'] puts "Soon, young padawan"
end
namespace :coverage do
desc "Delete aggregate coverage data."
task(:clean) { rm_f "coverage.data" }
end
desc "Run Rcov code coverage analysis"
RSpec::Core::RakeTask.new(:coverage) do |t|
t.rcov = true
t.verbose = true
t.rcov_opts = %q[--aggregate coverage.data --sort coverage --text-report --exclude "config,.bundle/*,gems/*,spec/*" -o doc/coverage -Ilib -i "noah.rb"]
end
if RUBY_ENGINE == 'jruby'
require 'warbler'
wt = Warbler::Task.new
task :default => wt.name
desc "Generate a configuration file to customize your archive"
task :config => "#{wt.name}:config"
desc "Install Warbler tasks in your Rails application"
task :pluginize => "#{wt.name}:pluginize"
desc "Feature: package gem repository inside a jar"
task :gemjar => "#{wt.name}:gemjar"
desc "Feature: make an executable archive"
task :executable => "#{wt.name}:executable"
desc "Feature: precompile all Ruby files"
task :compiled => "#{wt.name}:compiled"
desc "Display version of Warbler"
task :version => "#{wt.name}:version"
desc "Demo environment"
task :start_demo do
puts "Soon, young padawan"
end
end end
#!/usr/bin/env ruby #!/usr/bin/env ruby
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))) $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
require 'rubygems'
require 'noah' require 'noah'
require 'vegas' require 'vegas'
Vegas::Runner.new(Noah::App, 'noah') do |runner, opts, app| Vegas::Runner.new(Noah::App, 'noah') do |runner, opts, app|
opts.on("-r", "--redis URL", "redis url to connect to (default: redis://localhost:6379/0)") {|r| ENV["REDIS_URL"] = r } opts.on("-r", "--redis URL", "redis url to connect to (default: redis://localhost:6379/0)") {|r| ENV["REDIS_URL"] = r; Noah::App.set :redis_url, r }
end end
require 'sinatra/base' require File.join(File.dirname(__FILE__), 'version')
require 'sinatra/namespace'
require 'ohm'
require 'ohm/contrib'
require File.join(File.dirname(__FILE__), 'helpers') require File.join(File.dirname(__FILE__), 'helpers')
require File.join(File.dirname(__FILE__), 'models') require File.join(File.dirname(__FILE__), 'models')
...@@ -20,6 +16,7 @@ module Noah ...@@ -20,6 +16,7 @@ module Noah
set :raise_errors, false set :raise_errors, false
set :show_exceptions, false set :show_exceptions, false
set :run, false set :run, false
set :redis_url, ENV['REDIS_URL'] || 'redis://localhost:6379/0'
end end
configure(:development) do configure(:development) do
...@@ -40,7 +37,7 @@ module Noah ...@@ -40,7 +37,7 @@ module Noah
get '/' do get '/' do
content_type "text/html" content_type "text/html"
haml :index, :format => :html5 haml :index, :format => :html5, :locals => {:redis_url => settings.redis_url, :noah_version => Noah::VERSION}
end end
not_found do not_found do
...@@ -321,6 +318,5 @@ module Noah ...@@ -321,6 +318,5 @@ module Noah
end end
end end
# run! if app_file == $0
end end
end end
...@@ -25,12 +25,13 @@ class Configuration < Ohm::Model ...@@ -25,12 +25,13 @@ class Configuration < Ohm::Model
assert_present :name assert_present :name
assert_present :format assert_present :format
assert_present :body assert_present :body
assert_present :application_id
assert_unique [:name, :application_id] assert_unique [:name, :application_id]
end end
def to_hash def to_hash
application.nil? ? app=nil : app=Application[application_id].name Application[application_id].nil? ? app_name=nil : app_name=Application[application_id].name
super.merge(:name => name, :format => format, :body => body, :created_at => created_at, :updated_at => updated_at, :application => app) super.merge(:name => name, :format => format, :body => body, :created_at => created_at, :updated_at => updated_at, :application => app_name)
end end
def is_new? def is_new?
......
...@@ -2,15 +2,11 @@ ...@@ -2,15 +2,11 @@
$:.push File.expand_path("../lib", __FILE__) $:.push File.expand_path("../lib", __FILE__)
require "noah/version" require "noah/version"
def engine
defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
end
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "noah" s.name = "noah"
s.version = Noah::VERSION s.version = Noah::VERSION
s.platform = engine s.platform = Gem::Platform::RUBY
s.authors = ["lusis"] s.authors = ["John E. Vincent"]
s.email = ["lusis.org+rubygems.org@gmail.com"] s.email = ["lusis.org+rubygems.org@gmail.com"]
s.homepage = "https://github.com/lusis/noah" s.homepage = "https://github.com/lusis/noah"
s.summary = %q{Application registry based on Apache Zookeeper} s.summary = %q{Application registry based on Apache Zookeeper}
...@@ -26,26 +22,29 @@ Gem::Specification.new do |s| ...@@ -26,26 +22,29 @@ Gem::Specification.new do |s|
s.add_dependency("redis", ["= 2.1.1"]) s.add_dependency("redis", ["= 2.1.1"])
s.add_dependency("nest", ["= 1.1.0"]) s.add_dependency("nest", ["= 1.1.0"])
s.add_dependency("rack", ["= 1.2.1"]) s.add_dependency("rack", ["= 1.2.1"])
s.add_dependency("rake", ["= 0.8.7"]) s.add_dependency("tilt", ["= 1.2.2"])
s.add_dependency("tilt", ["= 1.2.1"])
s.add_dependency("sinatra", ["= 1.1.2"]) s.add_dependency("sinatra", ["= 1.1.2"])
s.add_dependency("sinatra-namespace", ["0.6.1"]) s.add_dependency("sinatra-namespace", ["0.6.1"])
s.add_dependency("ohm", ["= 0.1.3"]) s.add_dependency("ohm", ["= 0.1.3"])
s.add_dependency("ohm-contrib", ["= 0.1.1"]) s.add_dependency("ohm-contrib", ["= 0.1.1"])
s.add_dependency("haml", ["= 3.0.25"]) s.add_dependency("haml", ["= 3.0.25"])
s.add_dependency("vegas", ["= 0.1.8"]) s.add_dependency("vegas", ["= 0.1.8"])
s.add_dependency("yajl-ruby", ["= 0.7.9"]) if s.platform.to_s == 'ruby'
s.add_dependency("json", ["= 1.5.1"]) if s.platform.to_s == 'jruby'
s.add_dependency("thin", ["= 1.2.7"]) if s.platform.to_s == 'ruby' if RUBY_PLATFORM =~ /java/
s.add_dependency("jruby-openssl", ["= 0.7.3"]) if s.platform.to_s == 'jruby' s.add_dependency("jruby-openssl")
s.add_dependency("json")
s.add_development_dependency("warbler", ["= 1.2.1"])
else
s.add_dependency("yajl-ruby")
s.add_dependency("thin")
end
s.add_development_dependency("sinatra-reloader", ["= 0.5.0"]) s.add_development_dependency("sinatra-reloader", ["= 0.5.0"])
s.add_development_dependency("rspec", ["= 2.4.0"]) s.add_development_dependency("rspec", ["~> 2.5"])
s.add_development_dependency("rcov", ["= 0.9.9"]) if s.platform.to_s == 'ruby' s.add_development_dependency("rcov", ["= 0.9.9"])
s.add_development_dependency("rack-test", ["= 0.5.7"]) s.add_development_dependency("rack-test", ["= 0.5.7"])
s.add_development_dependency("ZenTest", ["= 4.4.2"]) s.add_development_dependency("ZenTest", ["= 4.5.0"])
s.add_development_dependency("autotest", ["= 4.4.6"]) s.add_development_dependency("autotest", ["= 4.4.6"])
s.add_development_dependency("autotest-growl", ["= 0.2.9"]) s.add_development_dependency("autotest-growl", ["= 0.2.9"])
s.add_development_dependency("warbler", ["= 1.2.1"]) if s.platform.to_s == 'java'
end end
...@@ -2,18 +2,23 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') ...@@ -2,18 +2,23 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "Using the Configuration Model", :reset_redis => true do describe "Using the Configuration Model", :reset_redis => true do
before(:all) do before(:all) do
@appdata1 = {:name => "my_application"} app = Application.create(:name => "my_application")
@appconf_string = {:name => "mystringconf", :format => "string", :body => "some_var"} app.save
@appconf_json = {:name => "myjsonconf", :format => "json", :body => @appconf_string.to_json} @appconf_string = {:name => "mystringconf", :format => "string", :body => "some_var", :application_id => app.id}
@appconf_json = {:name => "myjsonconf", :format => "json", :body => @appconf_string.to_json, :application_id => app.id}
@appconf_missing_name = @appconf_string.reject {|x| x == :name}
@appconf_missing_format = @appconf_string.reject {|x| x == :format}
@appconf_missing_body = @appconf_string.reject {|x| x == :body}
@appconf_missing_application = @appconf_string.reject {|x| x == :application_id}
end end
before(:each) do before(:each) do
Ohm.redis.flushdb Ohm.redis.flushdb
end end
after(:each) do after(:each) do
Ohm.redis.flushdb Ohm.redis.flushdb
end end
describe "should" do describe "should" do
it "create a new Configuration" do it "create a new Configuration" do
c = Configuration.create(@appconf_string) c = Configuration.create(@appconf_string)
c.valid?.should == true c.valid?.should == true
...@@ -28,20 +33,60 @@ describe "Using the Configuration Model", :reset_redis => true do ...@@ -28,20 +33,60 @@ describe "Using the Configuration Model", :reset_redis => true do
a = Configuration[c.id] a = Configuration[c.id]
a.should == c a.should == c
end end
it "update an existing Configuration via find_or_create" it "update an existing Configuration via find_or_create" do
it "delete an existing Configuration" c = Configuration.find_or_create(@appconf_string)
it "return all Configurations" c.valid?.should == true
c.is_new?.should == true
sleep(3)
c.body = "some_other_var"
c.save
c.body.should == "some_other_var"
c.is_new?.should == false
end
it "delete an existing Configuration" do
a = Configuration.find_or_create(@appconf_string)
b = Configuration.find(@appconf_string).first
b.should == a
a.delete
c = Configuration.find(@appconf_string).first
c.nil?.should == true
end
it "return all Configurations" do
a = Configuration.find_or_create(@appconf_string)
b = Configuration.find_or_create(@appconf_json)
c = Configurations.all
c.size.should == 2
c.member?(a).should == true
c.member?(b).should == true
end
end end
describe "should not" do describe "should not" do
it "create a new Configuration without a name" do
it "create a new Configuration without a name" a = Configuration.create(@appconf_missing_name)
it "create a new Configuration without a format" a.valid?.should == false
it "create a new Configuration without a body" a.errors.should == [[:name, :not_present]]
it "create a new Configuration without an Application" end
it "create a duplicate Configuration" it "create a new Configuration without a format" do
a = Configuration.create(@appconf_missing_format)
a.valid?.should == false
a.errors.should == [[:format, :not_present]]
end
it "create a new Configuration without a body" do
a = Configuration.create(@appconf_missing_body)
a.valid?.should == false
a.errors.should == [[:body, :not_present]]
end
it "create a new Confguration without an application" do
a = Configuration.create(@appconf_missing_application)
a.valid?.should == false
a.errors.should == [[:application_id, :not_present]]
end
it "create a duplicate Configuration" do
a = Configuration.create(@appconf_string)
b = Configuration.create(@appconf_string)
b.errors.should == [[[:name, :application_id], :not_unique]]
end
end end
end end
...@@ -85,8 +85,8 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_ ...@@ -85,8 +85,8 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
describe "DELETE" do describe "DELETE" do
before(:all) do before(:all) do
cparms = {:name => 'a', :format => 'string', :body => 'asdf'}
@a = Application.create(:name => 'delete_test_app') @a = Application.create(:name => 'delete_test_app')
cparms = {:name => 'a', :format => 'string', :body => 'asdf', :application_id => @a.id}
@a.configurations << Configuration.create(cparms) @a.configurations << Configuration.create(cparms)
@a.save @a.save
@c = @a.configurations.first @c = @a.configurations.first
......
require 'ohm'
begin
require 'yajl'
rescue LoadError
require 'json'
end
ENV['RACK_ENV'] = 'test'
ENV['REDIS_URL'] = 'redis://localhost:6379/3'
Ohm::connect
require File.join(File.dirname(__FILE__), '..', 'lib', 'noah') require File.join(File.dirname(__FILE__), '..', 'lib', 'noah')
require File.join(File.dirname(__FILE__), '..', 'lib', 'noah', 'app') require File.join(File.dirname(__FILE__), '..', 'lib', 'noah', 'app')
require 'rspec' require 'rspec'
require 'rack/test' require 'rack/test'
ENV['RACK_ENV'] = 'test'
ENV['REDIS_URL'] = 'redis://localhost:6379/3'
Ohm::connect
RSpec.configure do |config| RSpec.configure do |config|
config.color_enabled = true config.color_enabled = true
......
...@@ -4,6 +4,12 @@ ...@@ -4,6 +4,12 @@
#header #header
%h1 Sample links %h1 Sample links
%h2 System Information
%ul
%li
Noah Version: #{locals[:noah_version]}
%li
Redis URL: #{locals[:redis_url]}
#header #header
%h2 Hosts %h2 Hosts
%ul %ul
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment