Skip to content

Commit

Permalink
- Reorganized the spec-suite
Browse files Browse the repository at this point in the history
- Removed the need for an actual rails application to run the spec-suite
- Added three specs for a rails association that should be working with or without the plugin (which fail at the moment)
  • Loading branch information
Maran Hidskes committed Aug 13, 2009
1 parent 7cce087 commit 44c06c3
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
spec/log/test.log
.garlic
doc/*
34 changes: 8 additions & 26 deletions spec/app.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
# Testing app setup

##################
# Database schema
##################

ActiveRecord::Migration.suppress_messages do
ActiveRecord::Schema.define(:version => 0) do
create_table :users, :force => true do |t|
t.column "type", :string
end

create_table :posts, :force => true do |t|
t.column "author_id", :integer
t.column "category_id", :integer
t.column "inflamatory", :boolean
end

create_table :categories, :force => true do |t|
end

create_table :comments, :force => true do |t|
t.column "user_id", :integer
t.column "post_id", :integer
end
end
end

#########
# Models
#
Expand All @@ -39,6 +13,9 @@
# similar_posts is be a subset of this collection)
# - authors have commenters: users who have commented on their posts
#
# Following model is added to verify the has_many/belongs_to :through relationship still works (as it is currently broken)
# - authors have many assistants: they can access the posts of their author

class User < ActiveRecord::Base
has_many :comments
has_many :commented_posts, :through => :comments, :source => :post, :uniq => true
Expand Down Expand Up @@ -81,4 +58,9 @@ class Category < ActiveRecord::Base
class Comment < ActiveRecord::Base
belongs_to :user
belongs_to :post
end

class Assistant < ActiveRecord::Base
belongs_to :author
has_many :posts, :through => :author
end
24 changes: 24 additions & 0 deletions spec/db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ActiveRecord::Schema.define(:version => 0) do
create_table :users, :force => true do |t|
t.column "type", :string
end

create_table :posts, :force => true do |t|
t.column "author_id", :integer
t.column "category_id", :integer
t.column "inflamatory", :boolean
end

create_table :categories, :force => true do |t|
end

create_table :comments, :force => true do |t|
t.column "user_id", :integer
t.column "post_id", :integer
end

create_table :assistants, :force => true do |t|
t.column "author_id", :integer
t.column "name", :string
end
end
24 changes: 24 additions & 0 deletions spec/models/assistant_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
require File.expand_path(File.join(File.dirname(__FILE__), '../app'))

describe Assistant do
before(:each) do
@assistant = Assistant.create!(:name => "Jeroen")
@author = @assistant.create_author

@p1, @p2, @p3 = (1..3).map { @author.posts.create! }
end

it "should return correct number of posts" do
@assistant.posts.size.should == 3
end

it "should return the same posts as its author" do
@assistant.posts.should == @author.posts
end

it "should return the posts in the same order " do
@assistant.posts.should == [@p1, @p2, @p3]
end

end
33 changes: 27 additions & 6 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] ||= "test"
require File.expand_path(File.join(File.dirname(__FILE__), "../../../../config/environment"))
require 'spec/rails'
# ENV["RAILS_ENV"] ||= "test"
# require File.expand_path(File.join(File.dirname(__FILE__), "../../../../config/environment"))
require 'rubygems'

# require 'spec/rails'

require 'spec'
require 'rubygems'
require 'active_record'


Spec::Runner.configure do |config|
config.use_transactional_fixtures = true
config.use_instantiated_fixtures = false
config.fixture_path = RAILS_ROOT + '/spec/fixtures'

config.before(:suite) do
# ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/log/test.log")
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
load(File.dirname(__FILE__) + "/db/schema.rb")

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
require File.expand_path(File.dirname(__FILE__) + '/../init')
end

# config.before(:each) do
# # We need to truncate the database before each spec
# ActiveRecord::Base.connection.tables.each do |table|
# ActiveRecord::Base.connection.execute("DELETE FROM #{table}")
# ActiveRecord::Base.connection.execute("DELETE FROM sqlite_sequence where name='#{table}'")
# end
# end

# You can declare fixtures for each behaviour like this:
# describe "...." do
# fixtures :table_a, :table_b
Expand Down

0 comments on commit 44c06c3

Please sign in to comment.