Displaying articles with tag newblog

Frustrations with rSpec

Posted by sam, Sun Feb 24 22:32:00 UTC 2008

I'm working on the new blog, and I'm having some trouble with rSpec testing controllers and nested routes.

Here's my routes file

ActionController::Routing::Routes.draw do |map|
  map.root :controller => "frontpage"
  map.resources :posts, :has_many => :comments 
end 

And here is some of the controller specs I'm trying to test

require File.dirname(__FILE__) + '/../spec_helper'

describe CommentsController do
  describe "handling GET /posts/1/comments" do

    before(:each) do
      @comment = mock_model(Comment)
      Comment.stub!(:find).and_return(@comment)
      @post = mock_model(Post)
      @post.stub!(:comments)
      @post.comments.stub!(:find).and_return([@comment])
      Post.stub!(:find).and_return(@post)
    end

    def do_get
      get :index, :post_id =>@post.id 
    end

    it "should be successful" do
      do_get
      response.should be_success
    end

    it "should render index template" do
      do_get
      response.should render_template('index')
    end

    it "should find all comments" do
      Comment.should_receive(:find).with(:all).and_return([@comment])
      do_get
    end

    it "should assign the found comments for the view" do
      do_get
      assigns[:comments].should == [@comment]
    end
  end

Here's the controller

class CommentsController < ApplicationController
  # GET /comments
  # GET /comments.xml
  before_filter :load_post

  def index
    @comments = @post.comments.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @comments }
    end
  end
  protected 
  def load_post
    @post = Post.find(params[:post_id])
  end
end

Everything works, except for one spec:

When I try to run the spec on "it should find all comments" I get this error

Mock 'Class' expected :find with (:all) once, but received it 0 times

I don't know what to do. I'm trying to understand what I'm doing. Mocks and Stubs are a big leap of faith for someone who grew up using full blown fixtures. I hope my other specs aren't passing due to dumb luck or something like that.

Should I wait and try to do this in the Stories? Is it useful to to rSpec mocks and stubs for a nested resource?

Any ideas? Fire away in the comments.

BTW, I'm using the great article Rolling on Rails with Rails2.0 from Akita on Rails as a starting point for my new blog.

Thanks for the great article!

1 comment | Filed Under: | Tags: newblog

Planned Features on the new blog

Posted by sam, Thu Feb 21 23:05:55 UTC 2008

The most important thing for me on my new blog is composing articles. I like doing quick posts from the iPhone, and also posting from Textmate.

I have to rejigger/reinvent/fork/whatever the Textmate blogging bundle to accommodate ActiveResource based posting. Shouldn't be too terribly hard.

Also, if I have an inspiration to write, I'd like to be able to post on it from my iPhone. I'm going to come up with a separate interface so that it's lean, mean, and fast.

The textmate bundle for blogging is the most interesting feature so far. I'm getting back into my concepts of programming languages class at DePaul by learning how to write grammars and mini-languages. For those of you who dont know what I'm talking about, think back to grade school when you had to dialog sentences.

Now think of the different things you have to do on a part of a sentence. It's complicated, but fun.

More progress to come on this later.

Till next time,

Sam

0 comments | Filed Under: | Tags: newblog

OH HI, I HELP WIF YOUR FORMATTING

Posted by sam, Tue Feb 19 02:28:09 UTC 2008

I think I'm starting to get the hang of using Javascript now. I finally managed to preformatted text and code to look like it does when I use Textmate. I'm partial to Vibrant Ink

I CAN HAZ JAVASCRIPTZ

And this is going to be some ruby code.

def lolcat
  puts "I'm in ur textmate, Editing ur code"
end

If you think I'm not making any sense, you're obviously not familiar with the LOLCAT site. Its a complete riot

I CAN HAS CHEEZBURGER?
moar humorous pics

For comedy:

class RickJames
  def initialize(args)
    puts "I'm Rick James, Bitch"
  end  
end

Hold up, aren't you supposed to be eating your own dogfood with the new blog system your'e cooking up?

Yes, I am. I was just frustrated by not getting this stylesheet code highlighting to work.

All I needed to do was to go to Dan Webb's website and you'll get everything you need.

You'll need to download his code highlighter plugin, and also maybe the LowPro framework. You know the drill with subversion:

svn export http://svn.danwebb.net/external/lowpro/ (wherever you put this code)
svn export http://svn.danwebb.net/external/CodeHighlighter/trunk/ (wherever you put this code)

You do not need to go and install any of the code macros or filtered stuff that mephisto requires.

Also, earlier I was going to port blog pinging and other stuff to Fullerton. Well, I just signed up for Feedburner, so I managed to abstract away some of the work I need to do on my new blog.

0 comments | Filed Under: | Tags: newblog

One day's progress writing the new blog

Posted by sam, Mon Feb 18 17:01:14 UTC 2008

I'm happily working away on my new blog on my free time. I think I'm going to call it Fullerton, after the El stop I get on to ride to work every day.

Fullerton right now is very bare. I can post articles, and that's it. I've spent a lot of time trying to get the css working. The only data structure I have at this point is Articles. I have two controllers, articles, and frontpage. This morning I figured out how to get Atom feed helpers working in rails. So now I can get RSS syndication going.

I wonder which feed format is better to use: RSS or Atom? Should I provide both? Seems like a worthwhile endeavor.

I really like being able to type blog entries in Textmate and then having it post them out to Mephisto. I'm going to have to replicate this feature in Fullerton.

Luckily, ActiveResource provides me with a restful web service, replacing the balky ActionWebService. I have to fork off the Blogging textmate bundle (or create a new one) to enable Restful blogging.

So here's a thought:

POST http://localhost:3000/articles 
(active resource formatted xml, with authentication)

All I plan on doing at this point is the standard CRUD with active resource.

I hope to get that up and running today. Stay tuned.

On the design front, I have Markdown enabled for writing. Next up, I need to get vibrant ink styled filtered text macros enabled.

Routing wise, i'll have to get permalinks setup, and learn the real way to do rails routing. I've been getting by on just using Resources for now.

Another feature I hope to add is a tag cloud. That's later down the line

0 comments | Filed Under: | Tags: newblog

I'm going to write my own blog system in rails.

Posted by sam, Sun Feb 17 23:58:00 UTC 2008

I think I've outgrown Mephisto. I have to manage three Mephisto installations(including this blog), but it's turning into kind of a hassle.

I also want to fully learn more about the rails framework, beyond what I currently know.

In fact, I'm following the advice of Geoff Grosenbach

I’ll add to this and say that every beginning Rails developer should write their own blog software. It’s a great learning experience and you can try things that aren’t possible with just an app running on localhost. It’s also a great environment for learning without the pressure of a mission-critical app. When you’re working for a client and deploying an important application, you’ll have made all the beginner mistakes on your own time (hopefully).

Now, I'm no beginner. I've first learned about Rails while bored at work in December 2005, then later that night I dipped my toe into the framework on my windows machine following the classic Rollling with Ruby on Rails articles I've been using rails professionally since september 2006.

I'm not the only one who's doing a new rails blog. Josh Susser said it best recently,

Mephisto is a solid piece of software, but it's too big for me, and that makes it hard to modify to do what I want. It's development has also lagged - no new release in over a year! And, I wanted something that ran on Rails 2

Mephisto actually runs on Rails 2.0 right now. And the development of the framework has accelerated, somewhat.

Rick's actually moved development of Mephisto over to git. git://activereload.net/mephisto.git

I think this is a good sign.

Regardless, Mephisto is sometimes kind of bloated.

My goals on my new blog software.

  • I'm going to use Rspec the entire time.
  • I also want to be able to type blog entries from Textmate and post to the server.
  • Seeing how the ActionWebservice is gone, I think i'll have to use ActiveResource, and also modify Textmate's blogging bundle to accommodate ActiveResource for blogging.
  • Code Macros
  • Flickr Integration
  • Tag Clouds
  • Delicious integration
  • Built in thickbox javascripts
  • Markdown/html/Textile posting
  • Pinging to other weblog services.

And lastly, I have to pick a name.

I'm developing this in Git, but I wont make the repo public until it's somewhat usable

0 comments | Filed Under: | Tags: newblog