Skip to content

Instantly share code, notes, and snippets.

View buethling's full-sized avatar

Chris Lydon buethling

View GitHub Profile
22 let(:stories) { 2.times.map { Factory.create :story } }
23 it "should get all stories" do
24 @admin = Factory(:user, :email => "admin@test.com", :admin => true)
25 User.all.each { |u| puts u.inspect }
26 test_sign_in(@admin)
27 get 'admin'
28 assigns(:stories).should eq(stories)
29 end
@buethling
buethling / test.rb
Created October 12, 2011 01:27
test
let(:stories) { 2.times.map { Story.create } }
it "should get all of them" do
stories = Story.all
assigns(:stories).should == stories
end
@buethling
buethling / stories_controller_spec.rb
Created October 2, 2011 18:08
Stories conntroller spec
context "for logged in user" do
before do
@user = Factory(:user)
@story = Factory(:story)
@user.follow! @story
end
it "should set turn if it's not set" do
get :show, :id => 1
assigns(:turn).should == "Mike Hoxhuge"
1 class PhrasesController < ApplicationController
2 before_filter :authenticate, :only => [:create, :destroy]
3
4 def create
5 @phrase = @story.phrases.build(params[:phrase])
6 if @phrase.save
7 flash[:success] = "Micropost created!"
8 redirect_to @story
9 else
10 render 'pages/home'
@buethling
buethling / microposts
Created March 8, 2011 02:58
microposts
class MicropostsController < ApplicationController
before_filter :authenticate, :only => [:create, :destroy]
before_filter :authorized_user, :only => :destroy
.
.
.
def destroy
@micropost.destroy
redirect_back_or root_path
end
@buethling
buethling / SessionController
Created March 2, 2011 17:25
rails session controller
class SessionsController < ApplicationController
def new
@title = "Sign in"
end
def create
user = User.authenticate(params[:session][:email],
params[:session][:password])
if user.nil?
flash.now[:error] = "Invalid email/password combination."