Skip to content

Commit dff8b40

Browse files
committed
Added post file, setup mongo, added blog view.
1 parent 8b4e897 commit dff8b40

8 files changed

Lines changed: 39 additions & 0 deletions

File tree

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ gem "mongo_mapper"
88
gem "cucumber-sinatra"
99
gem "capybara"
1010
gem "factory_girl"
11+
gem "bson_ext"

factories/post.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Factory.define :post do |p|
2+
p.title "default title"
3+
end

features/blog.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Feature: The Hackety Blog
2+
Scenario: I can see the blog
3+
Given there is a blog post with the title "First Post"
4+
When I go to the blog page
5+
Then I should see "First Post"

features/step_definitions/blog.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Given /^there is a blog post with the title "([^"]*)"$/ do |title|
2+
Factory(:post, :title => title)
3+
end
4+

features/support/paths.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def path_to(page_name)
1313
when /the home\s?page/
1414
'/'
1515

16+
when /the blog page/
17+
'/blog'
18+
1619
# Add more mappings here.
1720
# Here is an example that pulls values out of the Regexp:
1821
#

hackety.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
require 'rubygems'
22
require 'sinatra'
3+
require 'mongo_mapper'
4+
5+
configure do
6+
MongoMapper.connection = Mongo::Connection.new('localhost')
7+
MongoMapper.database = 'hackety'
8+
Dir.glob("#{File.expand_path(File.dirname(__FILE__))}/models/*.rb").each do |f|
9+
require f
10+
end
11+
end
312

413
get "/" do
514
haml :index
615
end
16+
17+
get "/blog" do
18+
@posts = Post.all
19+
haml :blog_index
20+
end

models/post.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Post
2+
include MongoMapper::Document
3+
key :title, String
4+
timestamps!
5+
end
6+

views/blog_index.haml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%ul
2+
- @posts.each do |post|
3+
%li= post.title

0 commit comments

Comments
 (0)