Skip to content
This repository has been archived by the owner on Apr 26, 2022. It is now read-only.

Commit

Permalink
minor updates/cleanup
Browse files Browse the repository at this point in the history
red > green features

setup rcov + cucumber/rspec rake tasks
  • Loading branch information
Jeremiah Heller committed May 5, 2011
1 parent 78978e7 commit e067fb5
Show file tree
Hide file tree
Showing 16 changed files with 168 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -23,3 +23,5 @@ coverage/
.rvmrc
public/files
public/blog_post_assets/
cuc_coverage/
coverage.data
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -26,6 +26,8 @@ group :development, :test do
gem 'rspec-rails'
gem 'factory_girl'
gem 'webrat'
gem 'launchy'
gem 'rcov'
end

group :production do
Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Expand Up @@ -63,6 +63,7 @@ GEM
celerity (0.8.8)
childprocess (0.1.7)
ffi (~> 0.6.3)
configuration (1.2.0)
cucumber (0.10.0)
builder (>= 2.1.2)
diff-lcs (~> 1.1.2)
Expand Down Expand Up @@ -107,6 +108,9 @@ GEM
i18n (0.5.0)
json (1.4.6)
json_pure (1.5.1)
launchy (0.4.0)
configuration (>= 0.0.5)
rake (>= 0.8.1)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
Expand Down Expand Up @@ -138,6 +142,7 @@ GEM
rake (>= 0.8.7)
thor (~> 0.14.4)
rake (0.8.7)
rcov (0.9.9)
rdiscount (1.6.8)
rspec (2.5.0)
rspec-core (~> 2.5.0)
Expand Down Expand Up @@ -192,8 +197,10 @@ DEPENDENCIES
factory_girl
file_share (~> 0.1.8)
formtastic
launchy
mysql
rails (= 3.0.3)
rcov
rspec-rails
ruby-openid
sqlite3-ruby
Expand Down
12 changes: 10 additions & 2 deletions app/controllers/blog/posts_controller.rb
@@ -1,7 +1,11 @@
module Blog
class PostsController < ApplicationController
before_filter :require_user, :except => :index
# before_filter :require_post_read_access, :only => [:show]
# before_filter :require_post_write_access, :only => [:edit, :update, :destroy, :create, :delete_asset, :un_edit, :upload_handler]

def index
@posts = Post.limit(5)
@posts = Post.order('created_at DESC').limit(5)
end

def new
Expand All @@ -13,7 +17,8 @@ def create
@post.author = current_user
if @post.save
respond_to do |format|
format.html{ redirect_to edit_blog_post_path(@post), :notice => "Saved post: #{@post.title}" }
append = current_user.is_admin? ? '' : ' Publication is pending moderator approval.'
format.html{ redirect_to edit_blog_post_path(@post), :notice => "Saved post: #{@post.title}.#{append}" }
end
else
render :new
Expand All @@ -30,10 +35,13 @@ def edit
def update
@post = Post.find params[:id]
if @post.update_attributes params[:blog_post]
remove_editing_user_record_for @post
respond_to do |format|
format.html{ redirect_to blog_post_path(@post), :notice => "Updated post: #{@post.title}"}
end
else
@rel_dir = asset_path_for @post, :relative
@assets = list_assets_for @post
render :edit
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/blog/posts/_lead_in.html.erb
Expand Up @@ -6,7 +6,7 @@
<div style="padding: 10px;">
<p class="small_text"><em><%= nice_date(post.created_at) %></em></p>

<% last_p_index = (post.body.index('</p>') || 105) %>
<% last_p_index = (post.body.index('</p>', 700) || 700) %>
<%=raw post.body.truncate(last_p_index+5, :separator => "\n", :omission => '') %>

<p style="float: right; margin-right: 60px;"><span class="fake_button"><%= link_to_delete_post(post) %> | <%= link_to_edit_post(post) %></span> <%= link_to_read_more(post) %></p>
Expand Down
30 changes: 11 additions & 19 deletions features/create_blog_content.feature
Expand Up @@ -2,31 +2,23 @@ Feature: Create blog content
In order to submit content for publication
As a registered user
I want a simple interface to create blog posts

Background: non-admin (registered) user is logged in
Given I am logged in as a non-admin user
Background: logged in with a 'writer' account
Given I am logged in as "writer" user "john"

Scenario: write a new post
Given I am on the new post page
Given I am on the new blog post page
When I fill in "Title" with "Get the most from all your data"
And I fill in "Body" with "Unquestionably the biggest challenge facing any organization today is effectively locating, managing and analysing the constant stream of data."
And I select "Some Wiki-provided Category" from "Category"
And I press "Save"
Then I should see "Post saved! Publication is pending moderator review."
And I should be on the posts page
Then I should see "Saved post: Get the most from all your data"
And I should see "Publication is pending moderator approval"
And I should be on the edit blog post page for "Get the most from all your data"
And the post "Get the most from all your data" should be private

Scenario: update a published post
Given I am on the edit post page for "Published Post"
When I fill in "Body" with "[Update] - A few things have changed since my original post..."
Given I am on the edit blog post page for "Published Post"
When I fill in "blog_post[body]" with "[Update] - A few things have changed since my original post..."
And I press "Save"
Then I should see "Post updated!"
And I should be on the posts page
And the post "Published Post" should be public

Scenario: upload a file and have a download link to the file insert itself into the post body
Given I am on the new post page
When I click "Upload"
And select a file "SomeFile.doc" from my computer
And I press "OK"
Then I should see a publicly accessible link to "SomeFile.doc" in the post body field
Then I should see "Updated post: Published Post"
And I should be on the blog post page for "Published Post"
2 changes: 1 addition & 1 deletion features/event_calendar.feature
@@ -1,7 +1,7 @@
Feature: Event calendar

Background: I am logged in
Given I am logged in as "admin" user "joe"
Given I am logged in as "admin" user "admin"

Scenario: create a new event spanning multiple days
When I follow "Site Admin"
Expand Down
2 changes: 1 addition & 1 deletion features/file_share.feature
@@ -1,7 +1,7 @@
Feature: Manage file attachments

Background: I am logged in
Given I am logged in as "admin" user "joe"
Given I am logged in as "admin" user "admin"

Scenario: update file description
Given there is 1 existing file
Expand Down
10 changes: 9 additions & 1 deletion features/step_definitions/auth_steps.rb
@@ -1,6 +1,5 @@
Given /I am logged in as "([^"]*)" user "([^"]*)"/ do |type, username|
steps %Q{
Given a "#{type}" user "#{username}"
When I go to the login page
And I fill in "Username" with "#{username}"
And I fill in "Password" with "test-pass"
Expand All @@ -10,6 +9,15 @@
end

Given /a "([^"]*)" user "([^"]*)"/ do |type, username|
u = User.new({
:login => 'admin',
:email => 'admin@test.com',
:password => 'test-pass',
:password_confirmation => 'test-pass',
:first_name => 'Admin',
:last_name => 'istrator',
:is_admin => true
}) if User.count == 0
User.create!({
:login => username,
:email => "#{username}@test.com",
Expand Down
3 changes: 3 additions & 0 deletions features/step_definitions/blog_post_steps.rb
@@ -0,0 +1,3 @@
Then /^the post "([^"]*)" should be (private|public)$/ do |title, expected|
Blog::Post.find_by_title(title).published.should eq (expected == 'public')
end
16 changes: 9 additions & 7 deletions features/support/paths.rb
Expand Up @@ -26,13 +26,15 @@ def path_to(page_name)

when /the manage events page/
'/dashboard/event_calendar'

# Add more mappings here.
# Here is an example that pulls values out of the Regexp:
#
# when /^(.*)'s profile page$/i
# user_profile_path(User.find_by_login($1))


when /the edit blog post page for "(.*)"/
p = Blog::Post.find_by_title($1)
edit_blog_post_path(p)

when /the blog post page for "(.*)"/
p = Blog::Post.find_by_title($1)
blog_post_path(p)

else
begin
page_name =~ /the (.*) page/
Expand Down
25 changes: 25 additions & 0 deletions lib/tasks/rcov.rake
@@ -0,0 +1,25 @@
task :cleanup_rcov_files do
rm_rf 'coverage.data'
end

namespace :spec do
task(:rcov).clear_prerequisites.clear_actions
desc "Run all examples using rcov"
RSpec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
t.rcov = true
t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features,spec/*"]
t.rcov_opts << %[ --sort coverage --aggregate coverage.data --rails]
end
end

namespace :cucumber do
task(:rcov).clear_prerequisites.clear_actions
desc "Run cucumber features using rcov"
Cucumber::Rake::Task.new :rcov => :cleanup_rcov_files do |t|
t.cucumber_opts = %w{--format progress}
t.rcov = true
t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features,spec/*"]
t.rcov_opts << %[ --sort coverage --aggregate coverage.data --rails]
t.rcov_opts << %[ --output #{Rails.root}/cuc_coverage]
end
end
58 changes: 57 additions & 1 deletion spec/controllers/blog/posts_controller_spec.rb
Expand Up @@ -3,10 +3,23 @@
describe Blog::PostsController do

subject{ mock_model(Blog::Post) }

def mock_admin(stubs={})
stub_model(User, {:is_admin? => true})
end

def mock_user(stubs={})
stub_model(User, {:is_admin? => false})
end

before(:each) do
controller.stub(:require_user){ mock_user }
controller.stub(:current_user){ mock_user }
end

describe "GET 'index'" do
it "loads @posts" do
Blog::Post.stub(:limit){ [subject] }
Blog::Post.stub_chain(:order, :limit){ [subject] }
get :index
assigns(:posts).should eq [subject]
end
Expand Down Expand Up @@ -95,6 +108,49 @@
response.should render_template("blog/posts/edit")
end
end

describe "PUT 'update' (:id => int, :blog_post => {})" do
let(:params){ {:some => 'attributes'} }
before(:each) do
subject.stub(:title){ 'Updating post' }
subject.stub(:update_attributes).with(params.stringify_keys){ false }
controller.stub(:remove_editing_user_record_for).with(subject)
Blog::Post.stub(:find).with(1){ subject }
end
it "loads a @post from :id" do
put :update, :id => 1, :blog_post => params
assigns(:post).should eq subject
end
it "updates the @post from :blog_post" do
subject.should_receive(:update_attributes).with(params.stringify_keys)
put :update, :id => 1, :blog_post => params
end
context "update succeeds :)" do
before(:each) do
subject.stub(:update_attributes){ true }
end
it "removes the editing user record for @post" do
controller.should_receive(:remove_editing_user_record_for).with(subject)
put :update, :id => 1, :blog_post => params
end
it "redirects to the blog post path w/ a flash[:notice]" do
put :update, :id => 1, :blog_post => params
response.should redirect_to blog_post_path(subject)
flash[:notice].should_not be_nil
end
end
context "update fails :(" do
it "loads @rel_dir and @assets for @post" do
put :update, :id => 1, :blog_post => params
assigns(:rel_dir).should eq "blog_post_assets/blog_post_#{subject.id}"
assigns(:assets).should be_kind_of Array
end
it "renders blog/posts/edit" do
put :update, :id => 1, :blog_post => params
response.should render_template("blog/posts/edit")
end
end
end

describe "GET 'show' (:id => int)" do
before(:each) do
Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/blog_posts.yml
@@ -0,0 +1,6 @@
published_post:
id: <%= Fixtures.identify :published_post %>
title: Published Post
body: "Unquestionably the biggest challenge facing any organization today is effectively locating, managing and analysing the constant stream of data."
author_id: <%= Fixtures.identify :john %>
published: true
4 changes: 3 additions & 1 deletion spec/fixtures/categories.yml
@@ -1,4 +1,6 @@

category_some:
id: <%= Fixtures.identify :category_some %>
name: Some Wiki-provided Category
# == Schema Information
#
# Table name: categories
Expand Down
21 changes: 21 additions & 0 deletions spec/fixtures/users.yml
@@ -1,3 +1,24 @@
admin:
login: admin
email: admin@test.com
first_name: Admin
last_name: Istrator
crypted_password: 4aefd3d0dcdb4ef9566a3060de2e3407d8333f56eb5d2a03cffa4b640734c1860f46bcdb3982ccf29b2abb4b9144666d1dea9d8716a964bd851db5845e2639c2
password_salt: tMdwHsfW0Dtz3gUSiYF
persistence_token: 8243b331ccb01cdcc8d78d8351a46b4534a0185c6b249a39d18d37f5eea99f3c773cda6aefd3e12115d78c0cf2c0c93773751249c22200a61d9b538bbba98e11
perishable_token: p8BdzCpF1JBsPYlqDxAz
is_admin: true

john:
login: john
email: john@test.com
first_name: John
last_name: Doe
crypted_password: 4aefd3d0dcdb4ef9566a3060de2e3407d8333f56eb5d2a03cffa4b640734c1860f46bcdb3982ccf29b2abb4b9144666d1dea9d8716a964bd851db5845e2639c2
password_salt: tMdwHsfW0Dtz3gUSiYF
persistence_token: 8243b331ccb01cdcc8d78d8351a46b4534a0185c6b249a39d18d37f5eea99f3c773cda6aefd3e12115d78c0cf2c0c93773751249c22200a61d9b538bbba98e11
perishable_token: p8BdzCpF1JBsPYlqDxAz
is_admin: false

# == Schema Information
#
Expand Down

0 comments on commit e067fb5

Please sign in to comment.