Hi Sid

On Mar 18, 6:03 pm, Sid Wood <[email protected]> wrote:
> Hi there,
>
> I know this might be more of a RSpec question but I'm thinking maybe
> the DataMapper community might be better suited to help me out.
>
> I'm fairly new to DataMapper and RSpec and I'm trying to write a
> controller spec for an index action that will include DM query
> chaining.
>
> Here is a very simplified version of the Controller#index I'm working
> on (..)

In controller specs I always use mocks and add various method call
expectations. In your case I would write something like that:

describe Controller
  describe "GET index" do
    let(:widgets) { [] }
    subject { get :index, params }

    before { Widget.should_receive(:all).with(:order =>
[:name.asc].and_return(widgets) }

    context "with alpha param" do
      let(:params) { { "alpha" : "1" } }
      before
{ widgets.should_receive(:by_alpha).with(params["alpha"] }
      it { should be_successful }
    end

    context "with beta param" do
      let(:params) { { "beta" : "1" } }
      before { widgets.should_receive(:by_beta).with(params["beta"] }
      it { should be_successful }
    end
  end
end

Hope this helps.

Cheers!

# solnic

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to