Permalink
Browse files

added basic models and relations

  • Loading branch information...
1 parent 60b5c91 commit a9716ff262cf8907805ff06884024f350884d294 @bumi bumi committed Apr 28, 2012
View
@@ -49,6 +49,7 @@ group :test do
gem "mocha", "~> 0.10"
gem "factory_girl_rails", "~> 1.7", require: false
gem "database_cleaner", "~> 0.7"
+ gem 'mongoid-rspec'
end
group :development, :test do
View
@@ -134,6 +134,9 @@ GEM
activemodel (~> 3.1)
mongo (~> 1.3)
tzinfo (~> 0.3.22)
+ mongoid-rspec (1.4.4)
+ mongoid (~> 2.0)
+ rspec (~> 2)
multi_json (1.3.2)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
@@ -254,6 +257,7 @@ DEPENDENCIES
mini_magick
mocha (~> 0.10)
mongoid
+ mongoid-rspec
rabl
rails (= 3.2.3)
rspec-rails (~> 2.8)
View
@@ -0,0 +1,11 @@
+class Category
+ include Mongoid::Document
+
+ has_many :companies
+ has_many :tags
+
+ field :name, type: String
+
+ validates :name, presence: true
+
+end
View
@@ -2,6 +2,10 @@ class Company
include Mongoid::Document
include Mongoid::Timestamps
+
+ belongs_to :category
+ has_many :tags
+
field :name, :type => String
field :description, :type => String
field :street, :type => String
View
@@ -0,0 +1,10 @@
+class Tag
+ include Mongoid::Document
+
+ has_many :companies
+
+ field :name, type: String
+
+ validates :name, presence: true
+
+end
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe Category do
+
+ it { should have_many(:companies) }
+ it { should have_many(:tags) }
+ it { should validate_presence_of(:name) }
+
+end
@@ -0,0 +1,8 @@
+require 'spec_helper'
+
+describe Company do
+
+ it { should belong_to :category }
+ it { should have_many :tags }
+
+end
View
@@ -0,0 +1,7 @@
+require 'spec_helper'
+
+describe Tag do
+
+ it { should have_many(:companies) }
+
+end
View
@@ -7,7 +7,8 @@
RSpec.configure do |config|
config.mock_with :mocha
config.extend VCR::RSpec::Macros
-
+ config.include Mongoid::Matchers
+
config.before :suite do
#DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)

0 comments on commit a9716ff

Please sign in to comment.