Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 3 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 20, 2012
Bram Wijnands Fixed mongoid 31d42b2
Bram Wijnands Added victim class to hold name and telephone number e01fc3d
Bram Wijnands Merge branch 'development' of github.com:michel/Ringr into development
Conflicts:
	Gemfile
	Gemfile.lock
c6eedb8
Showing with 79 additions and 21 deletions.
  1. +3 −1 Gemfile
  2. +19 −0 Gemfile.lock
  3. +10 −0 app/models/victim.rb
  4. +1 −12 config/mongoid.yml
  5. +8 −0 spec/factories/victims.rb
  6. +28 −0 spec/models/victim_spec.rb
  7. +10 −8 spec/spec_helper.rb
View
4 Gemfile
@@ -1,6 +1,8 @@
source 'https://rubygems.org'
gem 'rails', '3.2.2'
+gem 'bson_ext', '1.6.1'
+gem 'mongoid', :git => 'git://github.com/mongoid/mongoid.git'
gem 'twilio-ruby'
gem 'heroku'
gem 'jquery-rails'
@@ -14,8 +16,8 @@ group :assets do
gem 'uglifier', '>= 1.0.3'
end
-
group :test, :development do
+ gem "faker"
gem 'rspec-rails'
gem 'cucumber-rails'
gem 'factory_girl_rails'
View
19 Gemfile.lock
@@ -1,3 +1,12 @@
+GIT
+ remote: git://github.com/mongoid/mongoid.git
+ revision: 0be2ecf10d84a598cbc4e4787afd9306c913f3c1
+ specs:
+ mongoid (3.0.0)
+ activemodel (~> 3.1)
+ mongo (~> 1.3)
+ tzinfo (~> 0.3.22)
+
GEM
remote: https://rubygems.org/
specs:
@@ -31,6 +40,9 @@ GEM
addressable (2.2.7)
archive-tar-minitar (0.5.2)
arel (3.0.2)
+ bson (1.6.1)
+ bson_ext (1.6.1)
+ bson (~> 1.6.1)
builder (3.0.0)
capybara (1.1.2)
mime-types (>= 1.16)
@@ -72,6 +84,8 @@ GEM
factory_girl_rails (1.7.0)
factory_girl (~> 2.6.0)
railties (>= 3.0.0)
+ faker (1.0.1)
+ i18n (~> 0.4)
ffi (1.0.11)
gherkin (2.9.1)
json (>= 1.4.6)
@@ -111,6 +125,8 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
+ mongo (1.6.1)
+ bson (~> 1.6.1)
multi_json (1.1.0)
netrc (0.7.1)
nokogiri (1.5.2)
@@ -208,14 +224,17 @@ PLATFORMS
ruby
DEPENDENCIES
+ bson_ext (= 1.6.1)
coffee-rails (~> 3.2.1)
cucumber-rails
database_cleaner
draper (~> 0.11.1)
factory_girl_rails
+ faker
haml-rails
heroku
jquery-rails
+ mongoid!
rails (= 3.2.2)
rspec-rails
ruby-debug19
View
10 app/models/victim.rb
@@ -0,0 +1,10 @@
+class Victim
+ include Mongoid::Document
+ field :telephone_number, type: Integer
+ field :name, type: String
+ field :filename, type: String
+ field :guid, type: String
+ validates_presence_of :name
+ validates_format_of :telephone_number, with: /^[\d]+$/
+ validates_length_of :telephone_number, in: 8..10
+end
View
13 config/mongoid.yml
@@ -1,20 +1,9 @@
development:
host: localhost
database: ringr_development
+ raise_not_found_error: false
test:
host: localhost
database: ringr_test
-# set these environment variables on your prod server
-production:
- host: <%= ENV['MONGOID_HOST'] %>
- port: <%= ENV['MONGOID_PORT'] %>
- username: <%= ENV['MONGOID_USERNAME'] %>
- password: <%= ENV['MONGOID_PASSWORD'] %>
- database: <%= ENV['MONGOID_DATABASE'] %>
- # slaves:
- # - host: slave1.local
- # port: 27018
- # - host: slave2.local
- # port: 27019
View
8 spec/factories/victims.rb
@@ -0,0 +1,8 @@
+# Read about factories at https://github.com/thoughtbot/factory_girl
+
+FactoryGirl.define do
+ factory :victim do
+ name { Faker::Internet.user_name }
+ telephone_number { ([*[*0..9]*5].shuffle[0..9].join) }
+ end
+end
View
28 spec/models/victim_spec.rb
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+describe Victim do
+ describe "validations" do
+ it { validate_presence_of(:name) }
+
+ it "is invalid when not only numbers are given as a telephone nr." do
+ Factory.build(:victim, telephone_number: "abcdefgh").should_not be_valid
+ Factory.build(:victim, telephone_number: "012345678a").should_not be_valid
+ end
+
+ it "is invalid when it's shorter than 8 numbers" do
+ Factory.build(:victim, telephone_number: "0123456").should_not be_valid
+ Factory.build(:victim, telephone_number: 0).should_not be_valid
+ end
+
+ it "is invalid when it's longer than 10 numbers" do
+ Factory.build(:victim, telephone_number: 12345678910).should_not be_valid
+ Factory.build(:victim, telephone_number: 1234567891011).should_not be_valid
+ end
+
+ it "is valid when 8 to 10 numbers are given" do
+ Factory.build(:victim, telephone_number: 1234567)
+ Factory.build(:victim, telephone_number: 12345678)
+ Factory.build(:victim, telephone_number: 123456789)
+ end
+ end
+end
View
18 spec/spec_helper.rb
@@ -16,17 +16,19 @@
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
-
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
-
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
- # examples within a transaction, remove the following line or assign false
- # instead of true.
- config.use_transactional_fixtures = true
+ config.include Mongoid::Matchers
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
+
+ config.before :each do
+ DatabaseCleaner.strategy = :truncation
+ DatabaseCleaner.start
+ DatabaseCleaner.clean
+ end
+
+ config.after do
+ end
end

No commit comments for this range

Something went wrong with that request. Please try again.