Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #187 from ArturG/rspec

Road to 100% coverage
  • Loading branch information...
commit e1d35c0d03981684dc198fcab898380aa9750a23 2 parents f820f9d + cf442d3
@PragTob PragTob authored
View
2  app/controllers/api/rels_controller.rb
@@ -6,4 +6,4 @@ def index
def show
@rel = Rel.first(:slug => params[:id])
end
-end
+end
View
7 app/controllers/application_controller.rb
@@ -1,14 +1,7 @@
class ApplicationController < ActionController::Base
protect_from_forgery
- helper_method :title
- def title t=nil
- @title = t unless t.blank?
- @title
- end
-
rescue_from CanCan::AccessDenied do |exception|
redirect_to login_url, :alert => exception.message
end
-
end
View
4 app/helpers/application_helper.rb
@@ -1,8 +1,4 @@
module ApplicationHelper
- def program_path program
- "/users/#{program.author_username}/programs/#{program.slug}"
- end
-
def markdown(text)
Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(hard_wrap: true), autolink: true).render(text).html_safe
end
View
4 app/presenters/question_presenter.rb
@@ -22,7 +22,7 @@ def collection_path
end
def edit_resource_path
- edit_question_path
+ edit_question_path(@question)
end
def apply_scope(chain)
@@ -30,6 +30,6 @@ def apply_scope(chain)
end
def answers_path
- question_answer_path(@question)
+ question_answers_path(@question)
end
end
View
4 app/presenters/support_presenter.rb
@@ -18,14 +18,14 @@ def collection_path
end
def edit_resource_path
- edit_support_question_path
+ edit_support_question_path(@support_question)
end
def resource_path(question)
if question
support_question_path(question)
else
- support_question_path(@question)
+ support_question_path(@support_question)
end
end
View
13 features/step_definitions/user_steps.rb
@@ -1,5 +1,5 @@
def login_user
- @user = User.create!(username: "test_user",
+ @user = User.create!(username: "test_user",
email: "test_user@example.com",
password: "foobar",
password_confirmation: "foobar")
@@ -20,6 +20,13 @@ def create_other_user
login_user unless @user
end
+Given /^a steve exists$/ do
+ @steve = User.create!(username: "steve",
+ email: "steve_user@example.com",
+ password: "foobar",
+ password_confirmation: "foobar")
+end
+
When /^I go to look at my profile page$/ do
visit user_path(@user)
end
@@ -73,3 +80,7 @@ def create_other_user
page.should have_content("Test user likes to edit his profile")
end
+Then(/^I should see 'Steve'$/) do
+ @user.following?(@steve).should == true
+ page.should have_link @steve.username
+end
View
8 features/users.feature
@@ -3,7 +3,8 @@ Feature: Manage account
As a user of this site, I can view and update my profile, see my followers
Background:
- Given a logged in user
+ Given a steve exists
+ And a logged in user
Scenario: View my profile
When I go to look at my profile page
@@ -23,4 +24,7 @@ Feature: Manage account
When I am following someone
And I click on the number of people I am following on my profile
Then I should see someone I'm following
-
+
+ Scenario: I should always follow steve and vice versa
+ When I click on the number of people I am following on my profile
+ Then I should see 'Steve'
View
7 spec/controllers/mailer_controller_spec.rb
@@ -88,6 +88,13 @@
ActionMailer::Base.deliveries.last.body.to_s.should match @message.body
end
end
+
+ describe 'empty message' do
+ it "returns exception" do
+ post :create
+ expect(subject).to render_template(:new)
+ end
+ end
end
context 'when user is not a moderator' do
View
1  spec/controllers/questions_controller_spec.rb
@@ -1,7 +1,6 @@
require 'spec_helper'
describe QuestionsController do
-
describe "GET index" do
context "with format atom" do
it "responds with success" do
View
19 spec/controllers/rel_controller_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+describe Api::RelsController do
+ let(:slug){Fabricate(:rel)}
+
+ describe "GET index" do
+ it "responds with success" do
+ get :index
+ response.should be_success
+ end
+ end
+
+ describe "GET show" do
+ it "responds with success" do
+ get :show
+ response.should be_success
+ end
+ end
+end
View
24 spec/controllers/static_controller_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe StaticController do
+ describe "GET root" do
+ it "responds with success" do
+ expect(:get => "/").to route_to(:controller => "static", :action => "root")
+ end
+ end
+
+ describe "GET api_root" do
+ it "should render api layout" do
+ get :api_root
+ response.should render_template(:layout => "api")
+ end
+ end
+
+ describe "GET newest_version" do
+ it "should render version of api" do
+ get :newest_version
+ response.header['Content-Type'].should include 'application/json'
+ response.body.should include "1.0.0".to_json
+ end
+ end
+end
View
7 spec/controllers/user_controller_spec.rb
@@ -50,4 +50,11 @@
expect(flash[:notice]).to eq("You're no longer following #{mozart.username}")
end
end
+
+ describe 'Deleted user' do
+ it 'should create new deleted user' do
+ get :deleted_user
+ response.should be_success
+ end
+ end
end
View
1  spec/fabricators/answer_fabricator.rb
@@ -1,4 +1,3 @@
Fabricator(:answer) do
description "MyString"
- user ""
end
View
1  spec/fabricators/question_fabricator.rb
@@ -1,4 +1,5 @@
Fabricator(:question) do
+ id "RandomID"
title "Title"
description "Description"
user
View
20 spec/helpers/program_helper_spec.rb
@@ -0,0 +1,20 @@
+require "spec_helper"
+
+describe ProgramsHelper do
+ let(:simple) { Fabricate(:program) }
+ let(:complicated) { Fabricate(:program, :author_username => nil) }
+
+ describe "#program_link" do
+ it "returns author's program path if author username exists" do
+ helper.program_link(simple).should == "#{link_to(simple.title.titleize,
+ user_program_path(simple.author_username, simple))}".html_safe
+ end
+
+ it "returns url by program's slug if author username doesn't exist" do
+ helper.program_link(complicated).should == "#{link_to(complicated.title.titleize,
+ url_for(:controller => '/programs',
+ :action => 'show',
+ :id => complicated.slug))}".html_safe
+ end
+ end
+end
View
20 spec/models/deleted_user_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe DeletedUser do
+
+ before do
+ @user = DeletedUser.new
+ end
+
+ it 'has deleted username' do
+ @user.username.should == 'Deleted User'
+ end
+
+ it 'has no email' do
+ @user.email.should == 'none'
+ end
+
+ it 'returns deleted user param' do
+ @user.to_param.should == 'deleted_user'
+ end
+end
View
14 spec/models/rel_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe Rel do
+
+ before do
+ @rel = Rel.create(:slug => 'text', :description => 'some text')
+ end
+
+ context 'to_param' do
+ it 'returns slug' do
+ @rel.to_param.should == 'text'
+ end
+ end
+end
View
16 spec/models/user_spec.rb
@@ -1,10 +1,10 @@
require 'spec_helper'
describe User do
-
- let(:bob){Fabricate(:user)}
+ let(:bob){Fabricate(:user, :username => 'hacker')}
let(:mozart){Fabricate(:user)}
-
+ let(:hello_world){Fabricate(:program, :author_username => bob.username)}
+
it 'can be created validly' do
bob.should be_valid
mozart.should be_valid
@@ -17,4 +17,14 @@
bob.reload
bob.following?(mozart).should be_false
end
+
+ describe 'programs' do
+ it 'should return programs list' do
+ bob.programs.class.should == Plucky::Query
+ hello_world.author_username.should == 'hacker'
+ bob.username.should == 'hacker'
+ bob.programs.count.should == 1
+ bob.programs.first.should == hello_world
+ end
+ end
end
View
46 spec/presenters/question_presenter_spec.rb
@@ -0,0 +1,46 @@
+require 'spec_helper'
+
+describe QuestionPresenter do
+
+ let(:question){Fabricate(:question)}
+ let(:another_question){Fabricate(:question, :id => 'AnotherID')}
+ let(:answer){Fabricate(:answer, :question_id => question.id)}
+
+ before do
+ @qp = QuestionPresenter.new(question)
+ end
+
+ context 'collection_path' do
+ it 'returns questions_path' do
+ @qp.collection_path.should == '/questions'
+ end
+ end
+
+ context 'edit_resource_path' do
+ it 'returns edit_question_path' do
+ @qp.edit_resource_path.should == '/questions/RandomID/edit'
+ end
+ end
+
+ context 'new_resource_path' do
+ it 'returns new_question_path' do
+ @qp.new_resource_path.should == '/questions/new'
+ end
+ end
+
+ context 'resource_path' do
+ it 'returns self question path if nil' do
+ @qp.resource_path(nil).should == '/questions/RandomID'
+ end
+
+ it 'returns question path if not nil' do
+ @qp.resource_path(another_question).should == '/questions/AnotherID'
+ end
+ end
+
+ context 'answers_path' do
+ it 'returns questions answer path' do
+ @qp.answers_path.should == '/questions/RandomID/answers'
+ end
+ end
+end
View
45 spec/presenters/support_presenter_spec.rb
@@ -0,0 +1,45 @@
+require 'spec_helper'
+
+describe SupportPresenter do
+
+ let(:question){Fabricate(:question)}
+ let(:another_question){Fabricate(:question, :id => 'AnotherID')}
+
+ before do
+ @sp = SupportPresenter.new(question)
+ end
+
+ context 'page_title' do
+ it 'returns support questions title' do
+ @sp.page_title.should == 'Support Questions'
+ end
+ end
+
+ context 'collection_path' do
+ it 'returns support questions_path' do
+ @sp.collection_path.should == '/support/questions'
+ end
+ end
+
+ context 'edit_resource_path' do
+ it 'returns edit_support_question_path' do
+ @sp.edit_resource_path.should == '/support/questions/RandomID/edit'
+ end
+ end
+
+ context 'new_resource_path' do
+ it 'returns new_support_question_path' do
+ @sp.new_resource_path.should == '/support/questions/new'
+ end
+ end
+
+ context 'resource_path' do
+ it 'returns self question path if nil' do
+ @sp.resource_path(nil).should == '/support/questions/RandomID'
+ end
+
+ it 'returns question path if not nil' do
+ @sp.resource_path(another_question).should == '/support/questions/AnotherID'
+ end
+ end
+end
View
2  spec/unit/sluggifier_spec.rb
@@ -22,6 +22,4 @@
end
end
end
-
-
end
Please sign in to comment.
Something went wrong with that request. Please try again.