Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@werner
Created July 1, 2014 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save werner/6c6560495099e29ffc01 to your computer and use it in GitHub Desktop.
Save werner/6c6560495099e29ffc01 to your computer and use it in GitHub Desktop.
Habtm and foreign key Bug
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.2'
#For Heroku
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
gem 'sqlite3'
group :development, :test do
# Use sqlite3 as the database for Active Record
gem 'debugger'
gem 'rails-erd'
#add rack-mini-profiler
gem 'rack-mini-profiler'
end
group :test do
gem 'cucumber-rails', :require => false
gem 'selenium-webdriver'
# database_cleaner is not required, but highly recommended
gem 'database_cleaner'
gem 'rspec-rails', '~> 3.0.0.beta'
gem 'factory_girl_rails'
gem 'faker'
end
gem 'pry-rails', :group => :development
#for authentication
gem 'devise'
gem 'devise-i18n'
gem 'devise-i18n-views'
#use haml instead of html
gem 'haml'
gem 'haml-rails'
#twitter bootstrap gem
gem 'bootstrap-sass', '~> 3.1.0'
#font-awesome gem
gem "font-awesome-rails"
#kaminari gem
gem 'kaminari'
#angularjs gem
gem 'angularjs-rails'
gem 'angular-rails-templates'
#the_role gem
gem 'the_role', '~> 2.3'
#Auditing and Versioning gem
gem 'paper_trail', '~> 3.0.0'
#pdf generating gem
gem 'prawn'
gem 'wicked_pdf'
#excel generating gem
gem 'axlsx', '~> 2.0'
gem 'axlsx_rails'
gem 'acts_as_xlsx'
gem 'zip-zip'
#puma web server
gem 'puma'
#thread gem
gem 'sidekiq'
#calculation gem
gem 'dentaku'
GEMFILE
system 'bundle'
end
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts do |t|
end
create_table :comments do |t|
end
create_table :comments_posts, id: false do |t|
t.references :post, null: false
t.references :comment, null: false
end
end
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
has_and_belongs_to_many :great_posts, join_table: :comments_posts, class_name: Post
end
class BugTest < Minitest::Test
def test_association_stuff
post = Post.create!
post.comments << Comment.create!
assert_equal 1, post.comments.count
assert_equal 1, Comment.count
assert_equal post.id, Comment.first.post.id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment