Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adjusted file structures

  • Loading branch information...
commit 8ff23009875b5f45aab34c50ee0154671a55557a 1 parent 270d19d
@nouse authored
View
1  cuba/app.rb
@@ -10,7 +10,6 @@ class Note < Ohm::Model
Cuba.plugin Cuba::Render
Cuba.plugin TextHelpers
-Cuba.use Rack::MethodOverride
Cuba.settings[:template_engine] = "slim"
if ENV["RACK_ENV"] == "development"
View
2  cuba/config.ru
@@ -2,8 +2,10 @@ require 'ohm'
$LOAD_PATH << File.expand_path(File.dirname(__FILE__)+"/lib")
require 'text_helpers'
+require 'custom_method_override'
Ohm.connect :db => 0
require './app'
+Cuba.use Rack::CustomMethodOverride
run Cuba
View
31 cuba/lib/custom_method_override.rb
@@ -0,0 +1,31 @@
+module Rack
+ class CustomMethodOverride
+ HTTP_METHODS = %w(PUT DELETE)
+
+ METHOD_OVERRIDE_PARAM_KEY = "_method".freeze
+
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ if env["REQUEST_METHOD"] == "POST"
+ method = method_override(env)
+ if HTTP_METHODS.include?(method)
+ env["rack.methodoverride.original_method"] = env["REQUEST_METHOD"]
+ env["REQUEST_METHOD"] = method
+ end
+ end
+
+ @app.call(env)
+ end
+
+ def method_override(env)
+ req = Request.new(env)
+ method = req.GET[METHOD_OVERRIDE_PARAM_KEY]
+ method.to_s.upcase
+ rescue EOFError
+ ""
+ end
+ end
+end
View
3  cuba/spec/spec_helper.rb
@@ -3,12 +3,12 @@
require 'ohm'
require 'machinist/object'
require 'text_helpers'
+require 'custom_method_override'
require 'cuba'
Ohm.connect :db => 1
RSpec.configure do |config|
- config.include TextHelpers, :type => :request
config.include TextHelpers, :type => :acceptance
config.before(:each) do |example|
@@ -17,6 +17,7 @@
end
CUBA_ROOT = File.dirname(__FILE__)+'/..'
+Cuba.use Rack::CustomMethodOverride
Capybara.app = Cuba
require CUBA_ROOT+'/app'
View
6 cuba/views/edit.slim
@@ -1,5 +1,4 @@
-form action="/notes/#{note.id}" method="post"
- input type="hidden" name="_method" value="put"
+form action="/notes/#{note.id}?_method=put" method="post"
label
| Description
br
@@ -12,7 +11,6 @@ form action="/notes/#{note.id}" method="post"
= note.body
br
input type="submit" value="Update"
-form action="/notes/#{note.id}" method="post"
- input type="hidden" name="_method" value="delete"
+form action="/notes/#{note.id}?_method=delete" method="post"
input type="submit" value='Remove'
== partial :back_to_top
View
2  sinatra+sequel/Gemfile
@@ -8,7 +8,5 @@ gem "forme"
group :development, :test do
gem 'capybara'
gem "ffaker"
- gem 'rspec'
gem 'machinist', "~>1.0.6"
- gem 'unicorn'
end
View
8 sinatra+sequel/config.ru
@@ -1,7 +1,11 @@
-require 'bundler/setup'
-
require 'sequel'
DB = Sequel.connect("postgres:///notes_dev")
+DB.create_table?(:notes) do
+ primary_key :id
+ text :title
+ text :body
+end
+
require './notes'
run Sinatra::Application
View
6 sinatra+sequel/lib/note.rb
@@ -0,0 +1,6 @@
+require 'sequel/model'
+
+class Note < Sequel::Model
+ plugin :prepared_statements_safe
+ plugin :forme
+end
View
17 sinatra+sequel/notes.rb
@@ -1,28 +1,15 @@
require 'sinatra'
-require 'sequel'
require 'slim'
-require 'forme'
$LOAD_PATH << File.dirname(__FILE__)+"/lib"
require 'text_helpers'
+require 'note'
require 'forme/sinatra'
+require 'forme'
configure :development do
set :slim, :pretty => true
end
-configure do
- DB.create_table?(:notes) do
- primary_key :id
- text :title
- text :body
- end
-
- class Note < Sequel::Model
- end
- Note.plugin :prepared_statements_safe
- Note.plugin :forme
-end
-
helpers TextHelpers
get '/' do
View
1  sinatra+sequel/spec/spec_helper.rb
@@ -17,6 +17,7 @@
SINATRA_ROOT = File.dirname(__FILE__)+'/..'
DB = Sequel.connect('postgres:///notes_test')
+require 'note'
set :environment, :test
set :root, SINATRA_ROOT
Capybara.app = Sinatra::Application
Please sign in to comment.
Something went wrong with that request. Please try again.