Skip to content

Commit a00d2f8

Browse files
committed
added some ideas
1 parent baa3ad8 commit a00d2f8

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
While reading the great Avdi's [Objects on Rails](http://objectsonrails.com/) I've came accross some interesting
2+
code I didn't understand really well.
3+
4+
Take a look at this
5+
```ruby
6+
# spec/models/blog_spec.rb
7+
require 'ostruct'
8+
describe Blog do
9+
# ...
10+
describe "#new_post" do
11+
before do
12+
@new_post = OpenStruct.new
13+
@it.post_source = ->{ @new_post }
14+
end
15+
it "returns a new post" do
16+
@it.new_post.must_equal @new_post
17+
end
18+
it "sets the post's blog reference to itself" do
19+
@it.new_post.blog.must_equal(@it)
20+
end
21+
end
22+
end
23+
```
24+
Avdi simply explains this spec with
25+
26+
{% blockquote %}
27+
Here, we substitute a lambda which simply returns an OpenStruct for the
28+
#post_source.
29+
{% endblockquote %}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
layout: post
3+
title: "converting object type in rails"
4+
date: 2012-06-02 13:39
5+
comments: true
6+
categories:
7+
---
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
layout: post
3+
title: "why does rails match parameters to filter with regex"
4+
date: 2012-06-23 20:58
5+
comments: true
6+
categories:
7+
---

0 commit comments

Comments
 (0)