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

cleanup. specs finished. gemtest

parent 03757a64
......@@ -10,3 +10,4 @@ tmp/*
*.war
.bundle
warbler/*
Gemfile.lock
......@@ -7,19 +7,18 @@ PATH
ohm (= 0.1.3)
ohm-contrib (= 0.1.1)
rack (= 1.2.1)
rake (= 0.8.7)
redis (= 2.1.1)
sinatra (= 1.1.2)
sinatra-namespace (= 0.6.1)
thin (= 1.2.7)
tilt (= 1.2.1)
thin
tilt (= 1.2.2)
vegas (= 0.1.8)
yajl-ruby (= 0.7.9)
yajl-ruby
GEM
remote: http://rubygems.org/
specs:
ZenTest (4.4.2)
ZenTest (4.5.0)
autotest (4.4.6)
ZenTest (>= 4.4.1)
autotest-growl (0.2.9)
......@@ -39,18 +38,16 @@ GEM
rack (1.2.1)
rack-test (0.5.7)
rack (>= 1.0)
rake (0.8.7)
rcov (0.9.9)
rcov (0.9.9-java)
redis (2.1.1)
rspec (2.4.0)
rspec-core (~> 2.4.0)
rspec-expectations (~> 2.4.0)
rspec-mocks (~> 2.4.0)
rspec-core (2.4.0)
rspec-expectations (2.4.0)
rspec (2.5.0)
rspec-core (~> 2.5.0)
rspec-expectations (~> 2.5.0)
rspec-mocks (~> 2.5.0)
rspec-core (2.5.1)
rspec-expectations (2.5.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.4.0)
rspec-mocks (2.5.0)
sinatra (1.1.2)
rack (~> 1.1)
tilt (~> 1.2)
......@@ -70,21 +67,20 @@ GEM
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
tilt (1.2.1)
tilt (1.2.2)
vegas (0.1.8)
rack (>= 1.0.0)
yajl-ruby (0.7.9)
yajl-ruby (0.8.1)
PLATFORMS
java
ruby
DEPENDENCIES
ZenTest (= 4.4.2)
ZenTest (= 4.5.0)
autotest (= 4.4.6)
autotest-growl (= 0.2.9)
noah!
rack-test (= 0.5.7)
rcov (= 0.9.9)
rspec (= 2.4.0)
rspec (~> 2.5)
sinatra-reloader (= 0.5.0)
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/rake_task'
task :default => [:spec]
task :test => [:spec]
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"
task :sample, :redis_url do |t, args|
require 'ohm'
begin
require 'yajl'
rescue LoadError
require 'json'
end
require File.join(File.dirname(__FILE__), 'lib','noah')
Ohm::connect(:url => args.redis_url)
Ohm::redis.flushdb
puts "Creating Host entry for 'localhost'"
......@@ -88,47 +91,7 @@ EOJ
puts "Sample data populated!"
end
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
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
desc "Demo environment"
task :start_demo do
puts "Soon, young padawan"
end
end
#!/usr/bin/env ruby
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
require 'rubygems'
require 'noah'
require 'vegas'
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
require 'sinatra/base'
require 'sinatra/namespace'
require 'ohm'
require 'ohm/contrib'
require File.join(File.dirname(__FILE__), 'version')
require File.join(File.dirname(__FILE__), 'helpers')
require File.join(File.dirname(__FILE__), 'models')
......@@ -20,6 +16,7 @@ module Noah
set :raise_errors, false
set :show_exceptions, false
set :run, false
set :redis_url, ENV['REDIS_URL'] || 'redis://localhost:6379/0'
end
configure(:development) do
......@@ -40,7 +37,7 @@ module Noah
get '/' do
content_type "text/html"
haml :index, :format => :html5
haml :index, :format => :html5, :locals => {:redis_url => settings.redis_url, :noah_version => Noah::VERSION}
end
not_found do
......@@ -321,6 +318,5 @@ module Noah
end
end
# run! if app_file == $0
end
end
......@@ -25,12 +25,13 @@ class Configuration < Ohm::Model
assert_present :name
assert_present :format
assert_present :body
assert_present :application_id
assert_unique [:name, :application_id]
end
def to_hash
application.nil? ? app=nil : app=Application[application_id].name
super.merge(:name => name, :format => format, :body => body, :created_at => created_at, :updated_at => updated_at, :application => app)
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_name)
end
def is_new?
......
......@@ -2,15 +2,11 @@
$:.push File.expand_path("../lib", __FILE__)
require "noah/version"
def engine
defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
end
Gem::Specification.new do |s|
s.name = "noah"
s.version = Noah::VERSION
s.platform = engine
s.authors = ["lusis"]
s.platform = Gem::Platform::RUBY
s.authors = ["John E. Vincent"]
s.email = ["lusis.org+rubygems.org@gmail.com"]
s.homepage = "https://github.com/lusis/noah"
s.summary = %q{Application registry based on Apache Zookeeper}
......@@ -26,26 +22,29 @@ Gem::Specification.new do |s|
s.add_dependency("redis", ["= 2.1.1"])
s.add_dependency("nest", ["= 1.1.0"])
s.add_dependency("rack", ["= 1.2.1"])
s.add_dependency("rake", ["= 0.8.7"])
s.add_dependency("tilt", ["= 1.2.1"])
s.add_dependency("tilt", ["= 1.2.2"])
s.add_dependency("sinatra", ["= 1.1.2"])
s.add_dependency("sinatra-namespace", ["0.6.1"])
s.add_dependency("ohm", ["= 0.1.3"])
s.add_dependency("ohm-contrib", ["= 0.1.1"])
s.add_dependency("haml", ["= 3.0.25"])
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'
s.add_dependency("jruby-openssl", ["= 0.7.3"]) if s.platform.to_s == 'jruby'
if RUBY_PLATFORM =~ /java/
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("rspec", ["= 2.4.0"])
s.add_development_dependency("rcov", ["= 0.9.9"]) if s.platform.to_s == 'ruby'
s.add_development_dependency("rspec", ["~> 2.5"])
s.add_development_dependency("rcov", ["= 0.9.9"])
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-growl", ["= 0.2.9"])
s.add_development_dependency("warbler", ["= 1.2.1"]) if s.platform.to_s == 'java'
end
......@@ -2,9 +2,14 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "Using the Configuration Model", :reset_redis => true do
before(:all) do
@appdata1 = {:name => "my_application"}
@appconf_string = {:name => "mystringconf", :format => "string", :body => "some_var"}
@appconf_json = {:name => "myjsonconf", :format => "json", :body => @appconf_string.to_json}
app = Application.create(:name => "my_application")
app.save
@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
before(:each) do
Ohm.redis.flushdb
......@@ -12,8 +17,8 @@ describe "Using the Configuration Model", :reset_redis => true do
after(:each) do
Ohm.redis.flushdb
end
describe "should" do
describe "should" do
it "create a new Configuration" do
c = Configuration.create(@appconf_string)
c.valid?.should == true
......@@ -28,20 +33,60 @@ describe "Using the Configuration Model", :reset_redis => true do
a = Configuration[c.id]
a.should == c
end
it "update an existing Configuration via find_or_create"
it "delete an existing Configuration"
it "return all Configurations"
it "update an existing Configuration via find_or_create" do
c = Configuration.find_or_create(@appconf_string)
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
describe "should not" do
it "create a new Configuration without a name"
it "create a new Configuration without a format"
it "create a new Configuration without a body"
it "create a new Configuration without an Application"
it "create a duplicate Configuration"
it "create a new Configuration without a name" do
a = Configuration.create(@appconf_missing_name)
a.valid?.should == false
a.errors.should == [[:name, :not_present]]
end
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
......@@ -85,8 +85,8 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
describe "DELETE" do
before(:all) do
cparms = {:name => 'a', :format => 'string', :body => 'asdf'}
@a = Application.create(:name => 'delete_test_app')
cparms = {:name => 'a', :format => 'string', :body => 'asdf', :application_id => @a.id}
@a.configurations << Configuration.create(cparms)
@a.save
@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', 'app')
require 'rspec'
require 'rack/test'
ENV['RACK_ENV'] = 'test'
ENV['REDIS_URL'] = 'redis://localhost:6379/3'
Ohm::connect
RSpec.configure do |config|
config.color_enabled = true
......
......@@ -4,6 +4,12 @@
#header
%h1 Sample links
%h2 System Information
%ul
%li
Noah Version: #{locals[:noah_version]}
%li
Redis URL: #{locals[:redis_url]}
#header
%h2 Hosts
%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