Permalink
Browse files

User spec for create_shout

  • Loading branch information...
1 parent 1b233ac commit cecb3308f205b8366378d5735bcbc2a405d4df7a @halogenandtoast halogenandtoast committed Mar 12, 2012
View
@@ -12,9 +12,9 @@ gem 'sqlite3'
group :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
+ gem 'bourne'
end
-
# Gems used only for assets and not required
# in production environments by default.
group :assets do
View
@@ -29,6 +29,8 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
+ bourne (1.0)
+ mocha (= 0.9.8)
builder (3.0.0)
clearance (0.12.0)
diesel (~> 0.1.4)
@@ -64,6 +66,8 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
+ mocha (0.9.8)
+ rake
multi_json (1.1.0)
paperclip (2.5.0)
activerecord (>= 2.3.0)
@@ -133,6 +137,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ bourne
clearance
coffee-rails (~> 3.2.1)
factory_girl_rails
@@ -1,8 +1,6 @@
class PhotoShoutsController < ApplicationController
def create
- photo_shout = PhotoShout.new(params[:photo_shout])
- shout = current_user.shouts.new(medium: photo_shout)
- shout.save
+ current_user.create_shout PhotoShout.new(params[:photo_shout])
redirect_to dashboard_path, notice: "Shouted!"
end
end
@@ -1,8 +1,6 @@
class TextShoutsController < ApplicationController
def create
- text_shout = TextShout.new(params[:text_shout])
- shout = current_user.shouts.new(medium: text_shout)
- shout.save
+ current_user.create_shout TextShout.new(params[:text_shout])
redirect_to dashboard_path, notice: "Shouted!"
end
end
View
@@ -1,4 +1,8 @@
class User < ActiveRecord::Base
include Clearance::User
has_many :shouts
+
+ def create_shout(medium)
+ shouts.create(medium: medium)
+ end
end
View
@@ -1,6 +1,10 @@
FactoryGirl.define do
factory :shout do
- body "some text"
user
end
+
+ factory :text_shout do
+ body "some text"
+ shout
+ end
end
@@ -0,0 +1,13 @@
+require 'spec_helper'
+
+describe User do
+ it "can #create_shout" do
+ text_shout = build(:text_shout)
+ user = create(:user)
+ shout = user.create_shout(text_shout)
+ shout.medium.body.should == text_shout.body
+ shout.user.should == user
+ shout.persisted?.should == true
+ text_shout.persisted?.should == true
+ end
+end
View
@@ -14,7 +14,7 @@
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
- # config.mock_with :mocha
+ config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr

0 comments on commit cecb330

Please sign in to comment.