Permalink
Browse files

added a bunch...

  • Loading branch information...
1 parent 5049a17 commit f0ea7439998d14364443eb73a4286d5a2c66d97a @drapergeek committed Mar 12, 2012
View
@@ -27,6 +27,7 @@ gem 'paperclip'
group :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
+ gem 'bourne'
end
# To use ActiveModel has_secure_password
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.15.0)
diesel (~> 0.1.5)
@@ -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.2)
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
@@ -0,0 +1,7 @@
+class UsersController < ApplicationController
+
+ def show
+ @user = User.find(params[:id])
+ @shouts = @user.shouts.current
+ end
+end
View
@@ -1,4 +1,9 @@
class User < ActiveRecord::Base
include Clearance::User
has_many :shouts
+
+ def create_shout(medium)
+ new_shout = shouts.create(medium: medium)
+ end
+
end
@@ -0,0 +1,4 @@
+<h1><%= @user.email %></h1>
+<div id="shouts">
+ <%= render @shouts %>
+</div>
View
@@ -3,5 +3,6 @@
resources :shouts, only: [:show]
resources :text_shouts, only: [:create]
resources :photo_shouts, only: [:create]
+ resources :users, only: [:show]
root to: "welcome#index"
end
View
@@ -1,8 +1,12 @@
FactoryGirl.define do
factory :shout do
- body "some text"
user
end
+ factory :text_shout do
+ body "some text"
+ shout
+ end
+
end
@@ -0,0 +1,12 @@
+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.persisted?.should == true
+ text_shout.persisted?.should == true
+ end
+end
View
@@ -8,18 +8,11 @@
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
- # == Mock Framework
- #
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
- #
- # config.mock_with :mocha
- # config.mock_with :flexmock
- # config.mock_with :rr
- config.mock_with :rspec
+ config.mock_with :mocha
config.include FactoryGirl::Syntax::Methods
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
- config.fixture_path = "#{::Rails.root}/spec/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

0 comments on commit f0ea743

Please sign in to comment.