Skip to content

Commit 0cabcee

Browse files
committed
Question Presenter spec
1 parent 0e3bb4e commit 0cabcee

6 files changed

Lines changed: 72 additions & 3 deletions

File tree

app/presenters/question_presenter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ def collection_path
2222
end
2323

2424
def edit_resource_path
25-
edit_question_path
25+
edit_question_path(@question)
2626
end
2727

2828
def apply_scope(chain)
2929
chain.no_supports
3030
end
3131

3232
def answers_path
33-
question_answer_path(@question)
33+
question_answers_path(@question)
3434
end
3535
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'spec_helper'
2+
3+
describe StaticController do
4+
describe "GET root" do
5+
it "responds with success" do
6+
expect(:get => "/").to route_to(:controller => "static", :action => "root")
7+
end
8+
end
9+
end
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
Fabricator(:answer) do
22
description "MyString"
3-
user ""
43
end

spec/fabricators/question_fabricator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Fabricator(:question) do
2+
id "RandomID"
23
title "Title"
34
description "Description"
45
user

spec/models/rel_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require 'spec_helper'
2+
3+
describe Rel do
4+
5+
before do
6+
@rel = Rel.create(:slug => 'text', :description => 'some text')
7+
end
8+
9+
context 'to_param' do
10+
it 'returns slug' do
11+
@rel.to_param.should == 'text'
12+
end
13+
end
14+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require 'spec_helper'
2+
3+
describe QuestionPresenter do
4+
5+
let(:question){Fabricate(:question)}
6+
let(:another_question){Fabricate(:question, :id => 'AnotherID')}
7+
let(:answer){Fabricate(:answer, :question_id => question.id)}
8+
9+
before do
10+
@qp = QuestionPresenter.new(question)
11+
end
12+
13+
context 'collection_path' do
14+
it 'returns questions_path' do
15+
@qp.collection_path.should == '/questions'
16+
end
17+
end
18+
19+
context 'edit_resource_path' do
20+
it 'returns edit_question_path' do
21+
@qp.edit_resource_path.should == '/questions/RandomID/edit'
22+
end
23+
end
24+
25+
context 'new_resource_path' do
26+
it 'returns new_question_path' do
27+
@qp.new_resource_path.should == '/questions/new'
28+
end
29+
end
30+
31+
context 'resource_path' do
32+
it 'returns self question path if nil' do
33+
@qp.resource_path(nil).should == '/questions/RandomID'
34+
end
35+
36+
it 'returns question path if not nil' do
37+
@qp.resource_path(another_question).should == '/questions/AnotherID'
38+
end
39+
end
40+
41+
context 'answers_path' do
42+
it 'returns questions answer path' do
43+
@qp.answers_path.should == '/questions/RandomID/answers'
44+
end
45+
end
46+
end

0 commit comments

Comments
 (0)