akki 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/features/archives.feature +2 -2
- data/features/articles.feature +60 -4
- data/features/feeds.feature +45 -0
- data/features/home_page.feature +15 -0
- data/features/pages.feature +28 -1
- data/features/step_definitions/env.rb +17 -0
- data/features/step_definitions/steps.rb +12 -5
- data/lib/akki/application.rb +34 -2
- data/lib/akki/article.rb +40 -27
- data/lib/akki/context.rb +5 -0
- data/lib/akki/version.rb +1 -1
- data/spec/application_spec.rb +114 -35
- data/spec/article_spec.rb +20 -7
- data/spec/context_spec.rb +11 -0
- data/spec/spec_helper.rb +18 -0
- metadata +24 -19
data/features/archives.feature
CHANGED
@@ -19,9 +19,9 @@ Feature: Archives
|
|
19
19
|
title: Article 1
|
20
20
|
date: 2008/04/23
|
21
21
|
"""
|
22
|
-
And I have the page "archives.haml"
|
22
|
+
And I have the page "archives.haml" with the contents
|
23
23
|
"""
|
24
|
-
- articles.each do |article|
|
24
|
+
- context.articles.each do |article|
|
25
25
|
%p= article.title
|
26
26
|
"""
|
27
27
|
When I visit "/archives"
|
data/features/articles.feature
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
Feature: Article Page
|
2
2
|
In order to display articles
|
3
3
|
As a user
|
4
|
-
I want to be able to view an article
|
4
|
+
I want to be able to view an article and it's relevant information
|
5
|
+
|
6
|
+
Scenario: Article url that does not exist
|
7
|
+
When I visit "/1983/11/11/article-that-does-not-exist"
|
8
|
+
Then I should see a 404 html status code
|
5
9
|
|
6
10
|
Scenario: Simple Article
|
7
11
|
Given I have the article file "1983-05-23-simple-article.txt"
|
@@ -11,12 +15,64 @@ Feature: Article Page
|
|
11
15
|
|
12
16
|
%p article content
|
13
17
|
"""
|
14
|
-
And the article
|
18
|
+
And I have the page "article.haml" with the contents
|
19
|
+
"""
|
20
|
+
%div.title= context.article.title
|
21
|
+
%div.content= render_article(context.article)
|
22
|
+
%a{:href => context.article.path}
|
23
|
+
"""
|
24
|
+
When I visit "/1983/05/23/simple-article"
|
25
|
+
Then I should see:
|
26
|
+
"""
|
27
|
+
<div class='title'>Simple Article</div>
|
28
|
+
<div class='content'><p>article content</p></div>
|
29
|
+
<a href='/1983/05/23/simple-article'></a>
|
30
|
+
"""
|
31
|
+
|
32
|
+
Scenario: Article referencing settings object
|
33
|
+
Given I have the article file "1983-05-23-simple-article.txt"
|
34
|
+
"""
|
35
|
+
title: Simple Article
|
36
|
+
date: 1983/05/23
|
37
|
+
|
38
|
+
= settings.title
|
39
|
+
= context.article.title
|
40
|
+
"""
|
41
|
+
And the application setting "title" with the value "The Blog Title"
|
42
|
+
And I have the page "article.haml" with the contents
|
43
|
+
"""
|
44
|
+
= render_article(context.article)
|
45
|
+
"""
|
46
|
+
And the application setting "title" with the value "The Blog Title"
|
47
|
+
When I visit "/1983/05/23/simple-article"
|
48
|
+
Then I should see:
|
49
|
+
"""
|
50
|
+
The Blog Title
|
51
|
+
Simple Article
|
52
|
+
"""
|
53
|
+
|
54
|
+
Scenario: Article does not get rendered with the layout
|
55
|
+
Given I have the article file "1983-05-23-simple-article.txt"
|
56
|
+
"""
|
57
|
+
title: Simple Article
|
58
|
+
date: 1983/05/23
|
59
|
+
|
60
|
+
article content
|
61
|
+
"""
|
62
|
+
And I have the view "layout.haml" with the contents
|
63
|
+
"""
|
64
|
+
Layout
|
65
|
+
= yield
|
66
|
+
"""
|
67
|
+
And I have the page "article.haml" with the contents
|
15
68
|
"""
|
16
|
-
|
69
|
+
Article
|
70
|
+
= render_article(context.article)
|
17
71
|
"""
|
18
72
|
When I visit "/1983/05/23/simple-article"
|
19
73
|
Then I should see:
|
20
74
|
"""
|
21
|
-
|
75
|
+
Layout
|
76
|
+
Article
|
77
|
+
article content
|
22
78
|
"""
|
@@ -0,0 +1,45 @@
|
|
1
|
+
Feature: Feeds
|
2
|
+
In order to notify users when there are new blog entries
|
3
|
+
As a blogger
|
4
|
+
I want to be able to expose my rss feeds
|
5
|
+
|
6
|
+
Scenario: Feed content type
|
7
|
+
Given I have the page "index.xml.haml" with the contents
|
8
|
+
"""
|
9
|
+
!!! XML
|
10
|
+
"""
|
11
|
+
When I visit "/index.xml"
|
12
|
+
Then the content type should be "application/atom+xml"
|
13
|
+
|
14
|
+
Scenario: Index page
|
15
|
+
Given I have the page "index.xml.haml" with the contents
|
16
|
+
"""
|
17
|
+
!!! XML
|
18
|
+
%feed{:xmlns => "http://www.w3.org/2005/Atom"}
|
19
|
+
%title
|
20
|
+
= settings.title
|
21
|
+
%id http://example.org
|
22
|
+
%updated
|
23
|
+
= context.articles.first.date.iso8601
|
24
|
+
"""
|
25
|
+
And I have the article file "1983-05-23-simple-article.txt"
|
26
|
+
"""
|
27
|
+
title: Simple Article
|
28
|
+
date: 1983/05/23
|
29
|
+
|
30
|
+
%p article content
|
31
|
+
"""
|
32
|
+
When I visit "/index.xml"
|
33
|
+
Then I should see:
|
34
|
+
"""
|
35
|
+
<?xml version='1.0' encoding='utf-8' ?>
|
36
|
+
<feed xmlns='http://www.w3.org/2005/Atom'>
|
37
|
+
<title>
|
38
|
+
The Blog Title
|
39
|
+
</title>
|
40
|
+
<id>http://example.org</id>
|
41
|
+
<updated>
|
42
|
+
1983-05-23
|
43
|
+
</updated>
|
44
|
+
</feed>
|
45
|
+
"""
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Feature: Home Page
|
2
|
+
In order to display a main page
|
3
|
+
As a blogger
|
4
|
+
I want to be able to render a home page view
|
5
|
+
|
6
|
+
Scenario: Simple home page
|
7
|
+
Given I have the page "index.haml" with the contents
|
8
|
+
"""
|
9
|
+
Welcome to my blog
|
10
|
+
"""
|
11
|
+
When I visit "/"
|
12
|
+
Then I should see:
|
13
|
+
"""
|
14
|
+
Welcome to my blog
|
15
|
+
"""
|
data/features/pages.feature
CHANGED
@@ -4,7 +4,7 @@ Feature: Pages
|
|
4
4
|
I want to display custom pages
|
5
5
|
|
6
6
|
Scenario: Page
|
7
|
-
Given I have the page "example-page.haml"
|
7
|
+
Given I have the page "example-page.haml" with the contents
|
8
8
|
"""
|
9
9
|
%p This is the example page
|
10
10
|
"""
|
@@ -17,3 +17,30 @@ Feature: Pages
|
|
17
17
|
Scenario: Page that doesn't exist
|
18
18
|
When I visit "/page-that-does-not-exist/"
|
19
19
|
Then I should see a 404 html status code
|
20
|
+
|
21
|
+
Scenario: Arbitrary articles can be rendered on a page
|
22
|
+
Given I have the article file "1983-05-23-simple-article.txt"
|
23
|
+
"""
|
24
|
+
title: Simple Article
|
25
|
+
date: 1983/05/23
|
26
|
+
|
27
|
+
%p article content
|
28
|
+
"""
|
29
|
+
And I have the article file "1982-04-01-arbitrary-article.txt"
|
30
|
+
"""
|
31
|
+
title: Arbitrary Article
|
32
|
+
date: 1982/04/01
|
33
|
+
|
34
|
+
%p arbitrary article content
|
35
|
+
"""
|
36
|
+
And I have the page "article.haml" with the contents
|
37
|
+
"""
|
38
|
+
Article
|
39
|
+
= render_article(context.articles.last)
|
40
|
+
"""
|
41
|
+
When I visit "/1983/05/23/simple-article"
|
42
|
+
Then I should see:
|
43
|
+
"""
|
44
|
+
Article
|
45
|
+
<p>arbitrary article content</p>
|
46
|
+
"""
|
@@ -8,3 +8,20 @@ require 'fileutils'
|
|
8
8
|
|
9
9
|
Capybara.app = Akki::Application
|
10
10
|
Akki::Application.set :environment, :test
|
11
|
+
Akki::Application.set :reload_templates, true
|
12
|
+
|
13
|
+
Before do
|
14
|
+
Akki::Article.reload_articles
|
15
|
+
end
|
16
|
+
|
17
|
+
module Akki
|
18
|
+
class Article
|
19
|
+
class << self
|
20
|
+
def reload_articles
|
21
|
+
if defined? @articles
|
22
|
+
remove_instance_variable :@articles
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -5,7 +5,6 @@ Before do
|
|
5
5
|
FileUtils.mkdir_p(@articles_path)
|
6
6
|
FileUtils.mkdir_p(@views_path)
|
7
7
|
FileUtils.mkdir_p(@pages_path)
|
8
|
-
Akki::Application.set :reload_templates, true
|
9
8
|
end
|
10
9
|
|
11
10
|
After do
|
@@ -19,13 +18,13 @@ Given /^I have the article file "([^"]*)"$/ do |article_file, article_contents|
|
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
|
-
Given /^the
|
23
|
-
File.open(File.join(@views_path,
|
21
|
+
Given /^I have the view "([^"]*)" with the contents$/ do |view, contents|
|
22
|
+
File.open(File.join(@views_path, view), 'w') do |file|
|
24
23
|
file.write(contents)
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
28
|
-
Given /^I have the page "([^"]*)"
|
27
|
+
Given /^I have the page "([^"]*)" with the contents$/ do |page, contents|
|
29
28
|
File.open(File.join(@pages_path, page), 'w') do |file|
|
30
29
|
file.write(contents)
|
31
30
|
end
|
@@ -37,10 +36,18 @@ Given /^I visit "([^"]*)"$/ do |url|
|
|
37
36
|
visit url
|
38
37
|
end
|
39
38
|
|
39
|
+
Given /^the application setting "([^"]*)" with the value "([^"]*)"$/ do |name, value|
|
40
|
+
Akki::Application.set name, value
|
41
|
+
end
|
42
|
+
|
40
43
|
Then /^I should see:$/ do |content|
|
41
|
-
page.source.should
|
44
|
+
page.source.chomp.should == content
|
42
45
|
end
|
43
46
|
|
44
47
|
Then /^I should see a (\d+) html status code$/ do |status_code|
|
45
48
|
page.status_code.should == status_code.to_i
|
46
49
|
end
|
50
|
+
|
51
|
+
Then /^the content type should be "([^"]*)"$/ do |content_type|
|
52
|
+
page.response_headers['Content-Type'].should == content_type
|
53
|
+
end
|
data/lib/akki/application.rb
CHANGED
@@ -1,14 +1,30 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
require 'akki/article'
|
3
|
+
require 'akki/context'
|
3
4
|
|
4
5
|
module Akki
|
5
6
|
class Application < Sinatra::Base
|
6
7
|
set :root, File.join(File.dirname(__FILE__), '..', '..')
|
7
8
|
|
9
|
+
attr_reader :context
|
10
|
+
|
11
|
+
def create_default_context
|
12
|
+
@context = Context.new
|
13
|
+
@context.articles = Article.all
|
14
|
+
end
|
15
|
+
|
16
|
+
before do
|
17
|
+
create_default_context
|
18
|
+
end
|
19
|
+
|
20
|
+
get '/?' do
|
21
|
+
render_page :index
|
22
|
+
end
|
23
|
+
|
8
24
|
get '/:page_name/?' do
|
9
25
|
page_name = params[:page_name].to_sym
|
10
26
|
pass unless settings.pages.include? page_name
|
11
|
-
|
27
|
+
render_page page_name
|
12
28
|
end
|
13
29
|
|
14
30
|
get "/:year/:month/:day/:slug/?" do
|
@@ -17,7 +33,23 @@ module Akki
|
|
17
33
|
day = params[:day].to_i
|
18
34
|
slug = params[:slug]
|
19
35
|
article = Article::find(year, month, day, slug)
|
20
|
-
|
36
|
+
pass unless article
|
37
|
+
|
38
|
+
@context.article = article
|
39
|
+
render_page :article
|
40
|
+
end
|
41
|
+
|
42
|
+
def render_page page = :index
|
43
|
+
if page.to_s.end_with? ".xml"
|
44
|
+
content_type :atom
|
45
|
+
haml :"pages/#{page}", :layout => false
|
46
|
+
else
|
47
|
+
haml :"pages/#{page}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def render_article article
|
52
|
+
haml article.content, :layout => false
|
21
53
|
end
|
22
54
|
end
|
23
55
|
end
|
data/lib/akki/article.rb
CHANGED
@@ -4,40 +4,53 @@ module Akki
|
|
4
4
|
class Article
|
5
5
|
attr_accessor :title, :slug, :date, :content
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@title = title
|
9
|
-
@date = date
|
10
|
-
@content = content
|
11
|
-
@slug = slug
|
7
|
+
def initialize(params)
|
8
|
+
@title = params[:title]
|
9
|
+
@date = params[:date]
|
10
|
+
@content = params[:content]
|
11
|
+
@slug = params[:slug]
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
16
|
-
article.date.year == year &&
|
17
|
-
article.date.month == month &&
|
18
|
-
article.date.day == day &&
|
19
|
-
article.slug == slug
|
20
|
-
}.first
|
14
|
+
def path
|
15
|
+
date.strftime("/%Y/%m/%d/") + slug
|
21
16
|
end
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
date = Date.strptime(yaml['date'], '%Y/%m/%d')
|
30
|
-
slug = File.basename(path).split("-", 4).last.gsub(".txt", "")
|
31
|
-
Article.new(title, date, content, slug)
|
18
|
+
class << self
|
19
|
+
def all
|
20
|
+
unless defined? @articles
|
21
|
+
@articles = get_all_articles
|
22
|
+
end
|
23
|
+
@articles
|
32
24
|
end
|
33
25
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
26
|
+
def find year, month, day, slug
|
27
|
+
article = all.select { |article|
|
28
|
+
article.date.year == year &&
|
29
|
+
article.date.month == month &&
|
30
|
+
article.date.day == day &&
|
31
|
+
article.slug == slug
|
32
|
+
}.first
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
38
36
|
|
39
|
-
|
40
|
-
|
37
|
+
def get_all_articles
|
38
|
+
Dir.glob("articles/*").map { |path|
|
39
|
+
get_article path
|
40
|
+
}.sort { |a, b| a.date <=> b.date }.reverse
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_article path
|
44
|
+
parts = File.read(path).split("\n\n", 2)
|
45
|
+
yaml = YAML.load(parts[0])
|
46
|
+
params = {
|
47
|
+
:content => parts[1],
|
48
|
+
:title => yaml['title'],
|
49
|
+
:date => Date.strptime(yaml['date'], '%Y/%m/%d'),
|
50
|
+
:slug => File.basename(path).split("-", 4).last.gsub(".txt", "")
|
51
|
+
}
|
52
|
+
Article.new(params)
|
53
|
+
end
|
41
54
|
end
|
42
55
|
end
|
43
56
|
end
|
data/lib/akki/context.rb
ADDED
data/lib/akki/version.rb
CHANGED
data/spec/application_spec.rb
CHANGED
@@ -17,9 +17,6 @@ module Akki
|
|
17
17
|
FileUtils.mkdir_p @views_path
|
18
18
|
FileUtils.mkdir_p @public_path
|
19
19
|
FileUtils.mkdir_p @pages_path
|
20
|
-
|
21
|
-
@pages = mock :pages
|
22
|
-
@pages.stub!(:all).and_return []
|
23
20
|
end
|
24
21
|
|
25
22
|
after do
|
@@ -27,48 +24,113 @@ module Akki
|
|
27
24
|
FileUtils.rm_rf @public_path
|
28
25
|
end
|
29
26
|
|
30
|
-
def
|
31
|
-
File.open(
|
27
|
+
def write_file path, contents
|
28
|
+
File.open(path, 'w') do |file|
|
32
29
|
file.write(contents)
|
33
30
|
end
|
34
31
|
end
|
35
32
|
|
33
|
+
def create_view name, contents
|
34
|
+
write_file(File.join(@views_path, name), contents)
|
35
|
+
end
|
36
|
+
|
36
37
|
def create_public name, contents
|
37
|
-
|
38
|
-
file.write(contents)
|
39
|
-
end
|
38
|
+
write_file(File.join(@public_path, name), contents)
|
40
39
|
end
|
41
40
|
|
42
41
|
def create_page name, contents
|
43
|
-
|
44
|
-
|
42
|
+
write_file(File.join(@pages_path, name), contents)
|
43
|
+
end
|
44
|
+
|
45
|
+
def mock_context(value = "the context value")
|
46
|
+
context = Context.new
|
47
|
+
context.value = value
|
48
|
+
Context.stub!(:new).and_return(context)
|
49
|
+
context
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "GET /" do
|
53
|
+
it "renders the index view" do
|
54
|
+
create_page "index.haml", "Home Page"
|
55
|
+
get "/"
|
56
|
+
last_response.body.should include "Home Page"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "passes the context object through to the index view" do
|
60
|
+
mock_context
|
61
|
+
create_page "index.haml", "= context.value"
|
62
|
+
get "/"
|
63
|
+
last_response.body.should == "the context value\n"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "adds the articles to the context object" do
|
67
|
+
context = mock_context
|
68
|
+
articles = mock(:articles).as_null_object
|
69
|
+
Article.stub!(:all).and_return(articles)
|
70
|
+
create_page 'index.haml', 'this is my page!'
|
71
|
+
context.should_receive(:articles=).with(articles)
|
72
|
+
get "/"
|
45
73
|
end
|
46
74
|
end
|
47
75
|
|
48
76
|
describe "GET /23/10/2011/simple-article" do
|
49
77
|
before do
|
50
78
|
@article = mock :article
|
51
|
-
@article.stub!(:render).and_return 'article content'
|
52
79
|
@article.stub!(:title).and_return 'article title'
|
80
|
+
@article.stub!(:content).and_return 'article content'
|
81
|
+
create_page "article.haml", "= render_article(context.article)"
|
82
|
+
Article.stub!(:all).and_return([@article])
|
53
83
|
Article.stub!(:find).and_return @article
|
54
84
|
end
|
55
85
|
|
86
|
+
it "passes the context object through to the article view" do
|
87
|
+
mock_context
|
88
|
+
create_page("article.haml", "= context.value")
|
89
|
+
get '/2011/10/23/simple-article'
|
90
|
+
last_response.body.should == "the context value\n"
|
91
|
+
end
|
92
|
+
|
93
|
+
it "passes the context object through to the article" do
|
94
|
+
mock_context
|
95
|
+
@article.stub!(:content).and_return("= context")
|
96
|
+
get '/2011/10/23/simple-article'
|
97
|
+
last_response.body.should include "the context value"
|
98
|
+
end
|
99
|
+
|
100
|
+
it "adds the article to the context object" do
|
101
|
+
context = mock_context
|
102
|
+
context.article = @article
|
103
|
+
context.should_receive(:article=).with(@article)
|
104
|
+
get '/2011/10/23/simple-article'
|
105
|
+
end
|
106
|
+
|
107
|
+
it "adds the articles to the context object" do
|
108
|
+
context = mock_context
|
109
|
+
articles = mock(:articles).as_null_object
|
110
|
+
Article.stub!(:all).and_return(articles)
|
111
|
+
create_page 'page_name.haml', 'this is my page!'
|
112
|
+
context.should_receive(:articles=).with(articles)
|
113
|
+
get '/2011/10/23/simple-article'
|
114
|
+
end
|
115
|
+
|
56
116
|
it "loads an article" do
|
57
|
-
|
117
|
+
create_page "article.haml", ""
|
58
118
|
Article.should_receive(:find).with(2011, 10, 23, "simple-article")
|
59
119
|
get '/2011/10/23/simple-article'
|
60
120
|
end
|
61
121
|
|
62
|
-
it "
|
63
|
-
create_view "
|
122
|
+
it "does not render the layout when rendering the article content" do
|
123
|
+
create_view "layout.haml", "Layout\n= yield"
|
124
|
+
create_page "article.haml", "Article\n= render_article(context.article)"
|
64
125
|
get '/2011/10/23/simple-article'
|
65
|
-
last_response.body.
|
126
|
+
last_response.body.should_not include "Layout\nArticle\nLayout\narticle content"
|
66
127
|
end
|
128
|
+
end
|
67
129
|
|
68
|
-
|
69
|
-
|
70
|
-
get '/2011/10/
|
71
|
-
last_response.
|
130
|
+
describe "GET /2011/10/01/article-that-does-not-exist" do
|
131
|
+
it "should 404" do
|
132
|
+
get '/2011/10/01/article-that-does-not-exist'
|
133
|
+
last_response.should be_not_found
|
72
134
|
end
|
73
135
|
end
|
74
136
|
|
@@ -80,26 +142,43 @@ module Akki
|
|
80
142
|
get '/page_name'
|
81
143
|
last_response.body.should include 'this is my page!'
|
82
144
|
end
|
83
|
-
end
|
84
145
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
146
|
+
it "passes the context object through to the page view" do
|
147
|
+
mock_context
|
148
|
+
Application.set :pages, [:page_name]
|
149
|
+
create_page "page_name.haml", "= context.value"
|
150
|
+
get '/page_name'
|
151
|
+
last_response.body.should == "the context value\n"
|
152
|
+
end
|
153
|
+
|
154
|
+
it "adds the articles to the context object" do
|
155
|
+
articles = mock(:articles).as_null_object
|
156
|
+
mock_context.should_receive(:articles=).with(articles)
|
157
|
+
Article.stub!(:all).and_return(articles)
|
158
|
+
create_page 'page_name.haml', 'this is my page!'
|
159
|
+
get '/page_name'
|
160
|
+
end
|
161
|
+
|
162
|
+
context "template name ending in .xml" do
|
163
|
+
before do
|
164
|
+
create_page "index.xml.haml", "!!! XML"
|
165
|
+
Application.set :pages, [:"index.xml"]
|
166
|
+
end
|
167
|
+
|
168
|
+
it "sets the content type to xml" do
|
169
|
+
get "/index.xml"
|
170
|
+
last_response.content_type.should == "application/atom+xml"
|
171
|
+
end
|
172
|
+
|
173
|
+
it "does not render the layout" do
|
174
|
+
create_view "layout.haml", "Layout"
|
175
|
+
get "/index.xml"
|
176
|
+
last_response.body.should_not include "Layout"
|
177
|
+
end
|
99
178
|
end
|
100
179
|
end
|
101
180
|
|
102
|
-
describe "GET page
|
181
|
+
describe "GET page that doesn't exist" do
|
103
182
|
it "404s" do
|
104
183
|
get '/page-that-does-not-exist'
|
105
184
|
last_response.should be_not_found
|
data/spec/article_spec.rb
CHANGED
@@ -3,11 +3,6 @@ require 'akki/article'
|
|
3
3
|
|
4
4
|
module Akki
|
5
5
|
describe Article do
|
6
|
-
it "renders the content" do
|
7
|
-
article = Article.new("an article", Date.new(2011, 10, 10), "%p article content", "an-article")
|
8
|
-
article.render.should include '<p>article content</p>'
|
9
|
-
end
|
10
|
-
|
11
6
|
def article_should_match article, title, date, content, slug
|
12
7
|
article.title.should == title
|
13
8
|
article.date.should == date
|
@@ -28,6 +23,18 @@ module Akki
|
|
28
23
|
article_should_match(Article.all.last, "article 2", Date.new(2011, 11, 25), "article 2 content", "article2")
|
29
24
|
end
|
30
25
|
|
26
|
+
it "only loads articles once" do
|
27
|
+
articles = [
|
28
|
+
"articles/2012-10-23-article1.txt",
|
29
|
+
"articles/2011-11-25-article2.txt"
|
30
|
+
]
|
31
|
+
Dir.should_receive(:glob).once.and_return(articles)
|
32
|
+
File.should_receive(:read).once.and_return("title: article 1\ndate: 2012/10/23\n\narticle 1 content")
|
33
|
+
File.should_receive(:read).once.and_return("title: article 2\ndate: 2011/11/25\n\narticle 2 content")
|
34
|
+
Article.all
|
35
|
+
Article.all
|
36
|
+
end
|
37
|
+
|
31
38
|
it "sorts articles by date" do
|
32
39
|
articles = [
|
33
40
|
"articles/2009-10-23-article1.txt",
|
@@ -36,17 +43,23 @@ module Akki
|
|
36
43
|
Dir.stub!(:glob).with("articles/*").and_return(articles)
|
37
44
|
File.stub!(:read).with(articles.first).and_return("title: article 1\ndate: 2009/10/23\n\narticle 1 content")
|
38
45
|
File.stub!(:read).with(articles.last).and_return("title: article 2\ndate: 2011/11/25\n\narticle 2 content")
|
46
|
+
|
39
47
|
Article.all.first.title.should == "article 2"
|
40
48
|
Article.all.last.title.should == "article 1"
|
41
49
|
end
|
42
50
|
|
43
51
|
it "finds an article" do
|
44
52
|
articles = [
|
45
|
-
Article.new("an article", Date.new(2011, 10, 10),
|
46
|
-
Article.new("Some Article", Date.new(2033, 4, 3),
|
53
|
+
Article.new({:title => "an article", :date => Date.new(2011, 10, 10), :slug => "an-article"}),
|
54
|
+
Article.new({:title => "Some Article", :date => Date.new(2033, 4, 3), :slug => "some-article"})
|
47
55
|
]
|
48
56
|
Article.stub!(:all).and_return(articles)
|
49
57
|
Article.find(2033, 4, 3, "some-article").should == articles.last
|
50
58
|
end
|
59
|
+
|
60
|
+
it "knows it's path" do
|
61
|
+
article = Article.new(:date => Date.new(1220, 5, 3), :slug => "the-article-slug")
|
62
|
+
article.path.should == "/1220/05/03/the-article-slug"
|
63
|
+
end
|
51
64
|
end
|
52
65
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,3 +3,21 @@ require 'akki'
|
|
3
3
|
require 'rack/test'
|
4
4
|
|
5
5
|
Akki::Application::set :environment, :test
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.before do
|
9
|
+
Akki::Article.reload_articles
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Akki
|
14
|
+
class Article
|
15
|
+
class << self
|
16
|
+
def reload_articles
|
17
|
+
if defined? @articles
|
18
|
+
remove_instance_variable :@articles
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: akki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
13
|
-
default_executable:
|
12
|
+
date: 2011-09-13 00:00:00.000000000Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: sinatra
|
17
|
-
requirement: &
|
16
|
+
requirement: &70275643805780 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ! '>='
|
@@ -22,10 +21,10 @@ dependencies:
|
|
22
21
|
version: '0'
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
24
|
+
version_requirements: *70275643805780
|
26
25
|
- !ruby/object:Gem::Dependency
|
27
26
|
name: haml
|
28
|
-
requirement: &
|
27
|
+
requirement: &70275643805140 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
29
|
requirements:
|
31
30
|
- - ! '>='
|
@@ -33,10 +32,10 @@ dependencies:
|
|
33
32
|
version: '0'
|
34
33
|
type: :runtime
|
35
34
|
prerelease: false
|
36
|
-
version_requirements: *
|
35
|
+
version_requirements: *70275643805140
|
37
36
|
- !ruby/object:Gem::Dependency
|
38
37
|
name: rake
|
39
|
-
requirement: &
|
38
|
+
requirement: &70275643804460 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
41
40
|
requirements:
|
42
41
|
- - ! '>='
|
@@ -44,10 +43,10 @@ dependencies:
|
|
44
43
|
version: '0'
|
45
44
|
type: :development
|
46
45
|
prerelease: false
|
47
|
-
version_requirements: *
|
46
|
+
version_requirements: *70275643804460
|
48
47
|
- !ruby/object:Gem::Dependency
|
49
48
|
name: rspec
|
50
|
-
requirement: &
|
49
|
+
requirement: &70275643803780 !ruby/object:Gem::Requirement
|
51
50
|
none: false
|
52
51
|
requirements:
|
53
52
|
- - ! '>='
|
@@ -55,10 +54,10 @@ dependencies:
|
|
55
54
|
version: '0'
|
56
55
|
type: :development
|
57
56
|
prerelease: false
|
58
|
-
version_requirements: *
|
57
|
+
version_requirements: *70275643803780
|
59
58
|
- !ruby/object:Gem::Dependency
|
60
59
|
name: cucumber
|
61
|
-
requirement: &
|
60
|
+
requirement: &70275643791240 !ruby/object:Gem::Requirement
|
62
61
|
none: false
|
63
62
|
requirements:
|
64
63
|
- - ! '>='
|
@@ -66,10 +65,10 @@ dependencies:
|
|
66
65
|
version: '0'
|
67
66
|
type: :development
|
68
67
|
prerelease: false
|
69
|
-
version_requirements: *
|
68
|
+
version_requirements: *70275643791240
|
70
69
|
- !ruby/object:Gem::Dependency
|
71
70
|
name: capybara
|
72
|
-
requirement: &
|
71
|
+
requirement: &70275643790500 !ruby/object:Gem::Requirement
|
73
72
|
none: false
|
74
73
|
requirements:
|
75
74
|
- - ! '>='
|
@@ -77,7 +76,7 @@ dependencies:
|
|
77
76
|
version: '0'
|
78
77
|
type: :development
|
79
78
|
prerelease: false
|
80
|
-
version_requirements: *
|
79
|
+
version_requirements: *70275643790500
|
81
80
|
description: ''
|
82
81
|
email:
|
83
82
|
- andrew.vos@gmail.com
|
@@ -94,17 +93,20 @@ files:
|
|
94
93
|
- config.ru
|
95
94
|
- features/archives.feature
|
96
95
|
- features/articles.feature
|
96
|
+
- features/feeds.feature
|
97
|
+
- features/home_page.feature
|
97
98
|
- features/pages.feature
|
98
99
|
- features/step_definitions/env.rb
|
99
100
|
- features/step_definitions/steps.rb
|
100
101
|
- lib/akki.rb
|
101
102
|
- lib/akki/application.rb
|
102
103
|
- lib/akki/article.rb
|
104
|
+
- lib/akki/context.rb
|
103
105
|
- lib/akki/version.rb
|
104
106
|
- spec/application_spec.rb
|
105
107
|
- spec/article_spec.rb
|
108
|
+
- spec/context_spec.rb
|
106
109
|
- spec/spec_helper.rb
|
107
|
-
has_rdoc: true
|
108
110
|
homepage: ''
|
109
111
|
licenses: []
|
110
112
|
post_install_message:
|
@@ -119,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
121
|
version: '0'
|
120
122
|
segments:
|
121
123
|
- 0
|
122
|
-
hash:
|
124
|
+
hash: 3090500227323535787
|
123
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
126
|
none: false
|
125
127
|
requirements:
|
@@ -128,19 +130,22 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
130
|
version: '0'
|
129
131
|
segments:
|
130
132
|
- 0
|
131
|
-
hash:
|
133
|
+
hash: 3090500227323535787
|
132
134
|
requirements: []
|
133
135
|
rubyforge_project: akki
|
134
|
-
rubygems_version: 1.
|
136
|
+
rubygems_version: 1.8.10
|
135
137
|
signing_key:
|
136
138
|
specification_version: 3
|
137
139
|
summary: ''
|
138
140
|
test_files:
|
139
141
|
- features/archives.feature
|
140
142
|
- features/articles.feature
|
143
|
+
- features/feeds.feature
|
144
|
+
- features/home_page.feature
|
141
145
|
- features/pages.feature
|
142
146
|
- features/step_definitions/env.rb
|
143
147
|
- features/step_definitions/steps.rb
|
144
148
|
- spec/application_spec.rb
|
145
149
|
- spec/article_spec.rb
|
150
|
+
- spec/context_spec.rb
|
146
151
|
- spec/spec_helper.rb
|