Skip to content

Instantly share code, notes, and snippets.

@williamhqs
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save williamhqs/c127e5d7018aa61cb02a to your computer and use it in GitHub Desktop.
Save williamhqs/c127e5d7018aa61cb02a to your computer and use it in GitHub Desktop.
Sinatra with activerecord transaction warnning.
class CreateStudent < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.integer :age
end
end
end
require "./myApp"
run MyApp.new
require "sinatra/activerecord"
set :database, {
:adapter => 'mysql2',
:encoding => 'utf8mb4',
:reconnect => true,
:database => 'test_development',
:pool => 5,
:username => 'root',
:password => '123123',
:host => 'localhost',
:socket => '/tmp/mysql.sock',
}
Myapp
---------------------
Gemfile
Rakefile
config.ru
db
----migrate
--------20150110033835_create_student.rb
----schema.rb
myApp.rb
Gemfile.lock
app
----controllers
----models
----student.rb
----views
database.rb
rspec
----myApp_spec.rb
----spec_helper.rb
source 'https://rubygems.org'
gem 'rake'
gem 'sinatra'
gem 'activerecord', '4.2', :require => 'active_record'
gem 'mysql2'
ROOT = File.expand_path('./..', __FILE__) unless defined?(ROOT)
require 'sinatra'
require 'active_record'
require './database'
['./app/controllers', './app/models', './app/views'].each do |path|
Dir.glob("#{ROOT}/#{path}/*.rb") do |filename|
require filename
end
end
class MyApp < Sinatra::Base
get '/' do
'Hello World!'
end
end
require './spec_helper'
describe "Main API" do
it "should respond to GET" do
get '/'
expect(response.status).to eq 200
end
end
require File.join(File.dirname(__FILE__), '..', 'myApp.rb')
require 'sinatra'
require 'rack/test'
set :environment, :test
set :run, false
set :raise_errors, true
set :logging, false
def app
Sinatra::Application
end
RSpec.configure do |config|
config.include Rack::Test::Methods
end
#after_commit with case the issue
class Student < ActiveRecord::Base
after_commit :print_hello
def print_hello
p "hello world"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment