Permalink
Browse files

simplified and hopefully more obvious config

  • Loading branch information...
1 parent da95bfe commit 59bf6b0a3d804531e0526756c1e3f3861c160167 @artemave artemave committed Jul 9, 2011
View
@@ -1,2 +1,4 @@
require 'bundler'
Bundler::GemHelper.install_tasks
+
+require 'sinatra/activerecord/rake'
View
@@ -0,0 +1,12 @@
+#!/usr/bin/env ruby
+require "irb"
+require 'bundler/setup'
+
+$:.push File.expand_path('../../lib', __FILE__)
+
+require 'fake_rest_services/config'
+AppConfig[:database] = File.expand_path('../../db/development.db', __FILE__)
+
+require 'fake_rest_services'
+
+IRB.start(__FILE__)
View
@@ -3,14 +3,14 @@
$:.push File.expand_path('../../lib', __FILE__)
require 'optparse'
-require 'fake_rest_services/options'
+require 'fake_rest_services/config'
OptionParser.new do |opts|
opts.on('-d', '--database FILENAME') do |fname|
- FakeRestServices::Options[:database] = fname
+ AppConfig[:database] = fname
end
opts.on('-p', '--port PORT', Integer) do |port|
- FakeRestServices::Options[:port] = port
+ AppConfig[:port] = port
end
end.parse!
@@ -1,4 +1,3 @@
-@wip
Feature: Persistence
In order to persist fixtrures/redirects between service restarts
As a developer
@@ -1,13 +1,13 @@
Given /^I (?:re)?start service without \-\-database option$/ do
- FakeRestServices::Options[:database] = ':memory:' #default value
- load 'fake_rest_services/config.rb'
+ AppConfig[:database] = ':memory:' #default value
+ load 'fake_rest_services/init.rb'
end
Then /^I should get "([^""]*)" in response status$/ do |status|
last_response.status.to_s.should == status
end
Given /^I (?:re)?start service with \-\-database "([^"]*)" option$/ do |db_path|
- FakeRestServices::Options[:database] = db_path
- load 'fake_rest_services/config.rb'
+ AppConfig[:database] = db_path
+ load 'fake_rest_services/init.rb'
end
@@ -1,12 +1,15 @@
require 'sinatra/base'
-require 'fake_rest_services/config'
+require 'fake_rest_services/init'
require 'fake_rest_services/models/fixture'
require 'fake_rest_services/models/redirect'
+require 'fake_rest_services/web_interface'
module FakeRestServices
class Application < Sinatra::Base
enable :logging
- set :port, Options[:port]
+ set :port, AppConfig[:port]
+
+ include WebInterface
post '/fixtures' do
Fixture.create(url: params['url'], content: params['content'])
@@ -1,11 +1,4 @@
-require 'sinatra/activerecord'
-require 'fake_rest_services/options'
-
-ActiveRecord::Base.establish_connection(
- adapter: "sqlite3",
- database: FakeRestServices::Options[:database]
-)
-
-ActiveRecord::Migrator.migrate(
- File.expand_path('../../../db/migrate', __FILE__)
-)
+AppConfig = {
+ database: ':memory:',
+ port: 4578
+}
@@ -0,0 +1,11 @@
+require 'sinatra/activerecord'
+require 'fake_rest_services/config'
+
+ActiveRecord::Base.establish_connection(
+ adapter: "sqlite3",
+ database: AppConfig[:database]
+)
+
+ActiveRecord::Migrator.migrate(
+ File.expand_path('../../../db/migrate', __FILE__)
+)
@@ -1,2 +1,4 @@
class Fixture < ActiveRecord::Base
+ #TODO rspec
+ validates_presence_of :url, :content
end
@@ -1,6 +0,0 @@
-module FakeRestServices
- Options = {
- database: ':memory:',
- port: 4578
- }
-end

0 comments on commit 59bf6b0

Please sign in to comment.