Permalink
Browse files

Added rspecs and removed text fixtures

  • Loading branch information...
1 parent 7915cbf commit a14e73c1669c259f9898db2e3304e10a8973b25e @arunsark committed May 13, 2011
View
1 .rspec
@@ -0,0 +1 @@
+--colour
View
12 Gemfile
@@ -31,6 +31,12 @@ gem 'devise'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
-# group :development, :test do
-# gem 'webrat'
-# end
+group :development, :test do
+ gem 'rspec-rails'
+# gem 'cucumber-rails'
+ gem 'launchy'
+ gem 'capybara'
+ gem 'database_cleaner'
+ gem 'mongoid-rspec'
+ gem 'factory_girl_rails'
+end
View
57 Gemfile.lock
@@ -33,12 +33,34 @@ GEM
bson (1.3.0)
bson_ext (1.3.0)
builder (2.1.2)
+ capybara (0.4.1.2)
+ celerity (>= 0.7.9)
+ culerity (>= 0.2.4)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (>= 0.0.27)
+ xpath (~> 0.1.3)
+ celerity (0.8.9)
+ childprocess (0.1.8)
+ ffi (~> 1.0.6)
+ configuration (1.2.0)
+ culerity (0.2.15)
+ database_cleaner (0.6.7)
devise (1.2.1)
bcrypt-ruby (~> 2.1.2)
orm_adapter (~> 0.0.3)
warden (~> 1.0.3)
+ diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
+ factory_girl (1.3.3)
+ factory_girl_rails (1.0.1)
+ factory_girl (~> 1.3)
+ railties (>= 3.0.0)
+ ffi (1.0.7)
+ rake (>= 0.8.7)
formtastic (1.2.3)
actionpack (>= 2.3.7)
activesupport (>= 2.3.7)
@@ -47,6 +69,10 @@ GEM
jquery-rails (0.2.7)
rails (~> 3.0)
thor (~> 0.14.4)
+ 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)
@@ -60,9 +86,13 @@ GEM
mongo (~> 1.3)
tzinfo (~> 0.3.22)
will_paginate (~> 3.0.pre)
+ mongoid-rspec (1.4.2)
+ mongoid (~> 2.0)
+ rspec (~> 2)
mongoid_slug (0.7.2)
mongoid (~> 2.0.0)
stringex (~> 1.2.0)
+ nokogiri (1.4.4)
orm_adapter (0.0.4)
polyglot (0.3.1)
rack (1.2.2)
@@ -84,6 +114,25 @@ GEM
rake (>= 0.8.7)
thor (~> 0.14.4)
rake (0.8.7)
+ rspec (2.5.0)
+ rspec-core (~> 2.5.0)
+ rspec-expectations (~> 2.5.0)
+ rspec-mocks (~> 2.5.0)
+ rspec-core (2.5.2)
+ rspec-expectations (2.5.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.5.0)
+ rspec-rails (2.5.0)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.5.0)
+ rubyzip (0.9.4)
+ selenium-webdriver (0.2.0)
+ childprocess (>= 0.1.7)
+ ffi (>= 1.0.7)
+ json_pure
+ rubyzip
stringex (1.2.1)
thor (0.14.6)
treetop (1.4.9)
@@ -92,15 +141,23 @@ GEM
warden (1.0.3)
rack (>= 1.0.0)
will_paginate (3.0.pre2)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
bson_ext
+ capybara
+ database_cleaner
devise
+ factory_girl_rails
formtastic
jquery-rails
+ launchy
mongoid
+ mongoid-rspec
mongoid_slug
rails (= 3.0.7)
+ rspec-rails
View
8 app/controllers/posts_controller.rb
@@ -44,9 +44,11 @@ def edit
# POST /posts.xml
def create
@post = Post.new(params[:post])
- @post.users << current_user
- logger.debug "Going to save #{Rails.logger.level} #{@post.title.inspect}"
- respond_to do |format|
+ unless params[:author].blank?
+ @post.users << User.find(params[:author])
+ end
+ logger.debug "Going to save #{Rails.logger.level} #{@post.title.inspect} #{params[:post]}"
+ respond_to do |format|
begin
@post.safely.save!
logger.debug "Saved successfully #{@post.title.inspect}"
View
15 app/models/post.rb
@@ -1,6 +1,7 @@
class Post
include Mongoid::Document
include Mongoid::Slug
+ include Mongoid::MultiParameterAttributes
attr_accessor :post_tags
attr_accessible :title, :content, :post_tags
@@ -10,11 +11,11 @@ class Post
field :published_on, :type => DateTime
field :tags, :type => Array
validates_presence_of :title, :content
- embeds_many :comments
+ embeds_many :comments, :dependent => :destroy
index :slug, unique:true
validates_uniqueness_of :title, :case_sensitive => false
- before_save :set_published_on, :generate_slug, :generate_tags
+ before_save :set_published_on, :generate_slug, :generate_tags
slug :slug
has_and_belongs_to_many :users
@@ -26,6 +27,16 @@ def get_tags
self.tags.inject{|tag_string,tag| tag_string + ", " + tag}
end
end
+
+ def authors
+ unless users.empty?
+ users.map{|user| user.nick_name}
+ .inject{|author_1,author_2| author_1 + ", " + author_2 }
+ else
+ "None"
+ end
+ end
+
private
def set_published_on
self.published_on = DateTime.now
View
4 app/models/user.rb
@@ -5,4 +5,8 @@ class User
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_and_belongs_to_many :posts
+
+ field :first_name
+ field :last_name
+ field :nick_name
end
View
9 app/views/devise/registrations/new.html.erb
@@ -3,6 +3,15 @@
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
+ <p><%= f.label :first_name %><br />
+ <%= f.text_field :first_name %></p>
+
+ <p><%= f.label :last_name %><br />
+ <%= f.text_field :last_name %></p>
+
+ <p><%= f.label :nick_name %><br />
+ <%= f.text_field :nick_name %></p>
+
<p><%= f.label :email %><br />
<%= f.email_field :email %></p>
View
12 app/views/posts/_form.html.erb
@@ -25,6 +25,18 @@
<%= f.label :tags %><br />
<%= f.text_field :post_tags %>
</div>
+ <div class="field">
+ <%= f.label :published_on %><br />
+ <%= f.datetime_select :published_on %>
+ </div>
+
+
+ <div class="field">
+ <%= f.label :author %><br />
+ <%= select_tag(:author,options_from_collection_for_select(User.all,:_id,:nick_name),:multiple=>true,:size=>3) %>
+ <%= options_from_collection_for_select(User.all,:_id,:nick_name) %>
+ </div>
+
<div class="actions">
<%= f.submit %>
</div>
View
1 app/views/posts/show.html.erb
@@ -6,6 +6,7 @@
<p>
<%= @post.content %>
</p>
+<p> Author(s) : <%= @post.authors %> </p>
<p> Tags : <%= @post.get_tags || "None" %> </p>
<%= link_to 'Edit', edit_post_path(@post) %> |
View
2 config/application.rb
@@ -5,7 +5,7 @@
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
-require "rails/test_unit/railtie"
+# require "rails/test_unit/railtie"
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
View
8 config/cucumber.yml
@@ -0,0 +1,8 @@
+<%
+rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
+rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
+std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
+%>
+default: <%= std_opts %> features
+wip: --tags @wip:3 --wip features
+rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
View
211 features/step_definitions/web_steps.rb
@@ -0,0 +1,211 @@
+# TL;DR: YOU SHOULD DELETE THIS FILE
+#
+# This file was generated by Cucumber-Rails and is only here to get you a head start
+# These step definitions are thin wrappers around the Capybara/Webrat API that lets you
+# visit pages, interact with widgets and make assertions about page content.
+#
+# If you use these step definitions as basis for your features you will quickly end up
+# with features that are:
+#
+# * Hard to maintain
+# * Verbose to read
+#
+# A much better approach is to write your own higher level step definitions, following
+# the advice in the following blog posts:
+#
+# * http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
+# * http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
+# * http://elabs.se/blog/15-you-re-cuking-it-wrong
+#
+
+
+require 'uri'
+require 'cgi'
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
+
+module WithinHelpers
+ def with_scope(locator)
+ locator ? within(*selector_for(locator)) { yield } : yield
+ end
+end
+World(WithinHelpers)
+
+# Single-line step scoper
+When /^(.*) within ([^:]+)$/ do |step, parent|
+ with_scope(parent) { When step }
+end
+
+# Multi-line step scoper
+When /^(.*) within ([^:]+):$/ do |step, parent, table_or_string|
+ with_scope(parent) { When "#{step}:", table_or_string }
+end
+
+Given /^(?:|I )am on (.+)$/ do |page_name|
+ visit path_to(page_name)
+end
+
+When /^(?:|I )go to (.+)$/ do |page_name|
+ visit path_to(page_name)
+end
+
+When /^(?:|I )press "([^"]*)"$/ do |button|
+ click_button(button)
+end
+
+When /^(?:|I )follow "([^"]*)"$/ do |link|
+ click_link(link)
+end
+
+When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
+ fill_in(field, :with => value)
+end
+
+When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
+ fill_in(field, :with => value)
+end
+
+# Use this to fill in an entire form with data from a table. Example:
+#
+# When I fill in the following:
+# | Account Number | 5002 |
+# | Expiry date | 2009-11-01 |
+# | Note | Nice guy |
+# | Wants Email? | |
+#
+# TODO: Add support for checkbox, select og option
+# based on naming conventions.
+#
+When /^(?:|I )fill in the following:$/ do |fields|
+ fields.rows_hash.each do |name, value|
+ When %{I fill in "#{name}" with "#{value}"}
+ end
+end
+
+When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
+ select(value, :from => field)
+end
+
+When /^(?:|I )check "([^"]*)"$/ do |field|
+ check(field)
+end
+
+When /^(?:|I )uncheck "([^"]*)"$/ do |field|
+ uncheck(field)
+end
+
+When /^(?:|I )choose "([^"]*)"$/ do |field|
+ choose(field)
+end
+
+When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
+ attach_file(field, File.expand_path(path))
+end
+
+Then /^(?:|I )should see "([^"]*)"$/ do |text|
+ if page.respond_to? :should
+ page.should have_content(text)
+ else
+ assert page.has_content?(text)
+ end
+end
+
+Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
+ regexp = Regexp.new(regexp)
+
+ if page.respond_to? :should
+ page.should have_xpath('//*', :text => regexp)
+ else
+ assert page.has_xpath?('//*', :text => regexp)
+ end
+end
+
+Then /^(?:|I )should not see "([^"]*)"$/ do |text|
+ if page.respond_to? :should
+ page.should have_no_content(text)
+ else
+ assert page.has_no_content?(text)
+ end
+end
+
+Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
+ regexp = Regexp.new(regexp)
+
+ if page.respond_to? :should
+ page.should have_no_xpath('//*', :text => regexp)
+ else
+ assert page.has_no_xpath?('//*', :text => regexp)
+ end
+end
+
+Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
+ with_scope(parent) do
+ field = find_field(field)
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
+ if field_value.respond_to? :should
+ field_value.should =~ /#{value}/
+ else
+ assert_match(/#{value}/, field_value)
+ end
+ end
+end
+
+Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
+ with_scope(parent) do
+ field = find_field(field)
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
+ if field_value.respond_to? :should_not
+ field_value.should_not =~ /#{value}/
+ else
+ assert_no_match(/#{value}/, field_value)
+ end
+ end
+end
+
+Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
+ with_scope(parent) do
+ field_checked = find_field(label)['checked']
+ if field_checked.respond_to? :should
+ field_checked.should be_true
+ else
+ assert field_checked
+ end
+ end
+end
+
+Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
+ with_scope(parent) do
+ field_checked = find_field(label)['checked']
+ if field_checked.respond_to? :should
+ field_checked.should be_false
+ else
+ assert !field_checked
+ end
+ end
+end
+
+Then /^(?:|I )should be on (.+)$/ do |page_name|
+ current_path = URI.parse(current_url).path
+ if current_path.respond_to? :should
+ current_path.should == path_to(page_name)
+ else
+ assert_equal path_to(page_name), current_path
+ end
+end
+
+Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
+ query = URI.parse(current_url).query
+ actual_params = query ? CGI.parse(query) : {}
+ expected_params = {}
+ expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
+
+ if actual_params.respond_to? :should
+ actual_params.should == expected_params
+ else
+ assert_equal expected_params, actual_params
+ end
+end
+
+Then /^show me the page$/ do
+ save_and_open_page
+end
View
39 features/support/env.rb
@@ -0,0 +1,39 @@
+# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
+# It is recommended to regenerate this file in the future when you upgrade to a
+# newer version of cucumber-rails. Consider adding your own code to a new file
+# instead of editing this one. Cucumber will automatically load all features/**/*.rb
+# files.
+
+require 'cucumber/rails'
+
+# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
+# order to ease the transition to Capybara we set the default here. If you'd
+# prefer to use XPath just remove this line and adjust any selectors in your
+# steps to use the XPath syntax.
+Capybara.default_selector = :css
+
+# By default, any exception happening in your Rails application will bubble up
+# to Cucumber so that your scenario will fail. This is a different from how
+# your application behaves in the production environment, where an error page will
+# be rendered instead.
+#
+# Sometimes we want to override this default behaviour and allow Rails to rescue
+# exceptions and display an error page (just like when the app is running in production).
+# Typical scenarios where you want to do this is when you test your error pages.
+# There are two ways to allow Rails to rescue exceptions:
+#
+# 1) Tag your scenario (or feature) with @allow-rescue
+#
+# 2) Set the value below to true. Beware that doing this globally is not
+# recommended as it will mask a lot of errors for you!
+#
+ActionController::Base.allow_rescue = false
+
+# Remove/comment out the lines below if your app doesn't have a database.
+# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
+begin
+ DatabaseCleaner.strategy = :transaction
+rescue NameError
+ raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
+end
+
View
33 features/support/paths.rb
@@ -0,0 +1,33 @@
+module NavigationHelpers
+ # Maps a name to a path. Used by the
+ #
+ # When /^I go to (.+)$/ do |page_name|
+ #
+ # step definition in web_steps.rb
+ #
+ def path_to(page_name)
+ case page_name
+
+ when /the home\s?page/
+ '/'
+
+ # 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))
+
+ else
+ begin
+ page_name =~ /the (.*) page/
+ path_components = $1.split(/\s+/)
+ self.send(path_components.push('path').join('_').to_sym)
+ rescue Object => e
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
+ "Now, go and add a mapping in #{__FILE__}"
+ end
+ end
+ end
+end
+
+World(NavigationHelpers)
View
39 features/support/selectors.rb
@@ -0,0 +1,39 @@
+module HtmlSelectorsHelpers
+ # Maps a name to a selector. Used primarily by the
+ #
+ # When /^(.+) within (.+)$/ do |step, scope|
+ #
+ # step definitions in web_steps.rb
+ #
+ def selector_for(locator)
+ case locator
+
+ when /the page/
+ "html > body"
+
+ # Add more mappings here.
+ # Here is an example that pulls values out of the Regexp:
+ #
+ # when /the (notice|error|info) flash/
+ # ".flash.#{$1}"
+
+ # You can also return an array to use a different selector
+ # type, like:
+ #
+ # when /the header/
+ # [:xpath, "//header"]
+
+ # This allows you to provide a quoted selector as the scope
+ # for "within" steps as was previously the default for the
+ # web steps:
+ when /"(.+)"/
+ $1
+
+ else
+ raise "Can't find mapping from \"#{locator}\" to a selector.\n" +
+ "Now, go and add a mapping in #{__FILE__}"
+ end
+ end
+end
+
+World(HtmlSelectorsHelpers)
View
57 lib/tasks/cucumber.rake
@@ -0,0 +1,57 @@
+# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
+# It is recommended to regenerate this file in the future when you upgrade to a
+# newer version of cucumber-rails. Consider adding your own code to a new file
+# instead of editing this one. Cucumber will automatically load all features/**/*.rb
+# files.
+
+
+unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
+
+vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
+$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
+
+begin
+ require 'cucumber/rake/task'
+
+ namespace :cucumber do
+ Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
+ t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
+ t.fork = true # You may get faster startup if you set this to false
+ t.profile = 'default'
+ end
+
+ Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
+ t.binary = vendored_cucumber_bin
+ t.fork = true # You may get faster startup if you set this to false
+ t.profile = 'wip'
+ end
+
+ Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
+ t.binary = vendored_cucumber_bin
+ t.fork = true # You may get faster startup if you set this to false
+ t.profile = 'rerun'
+ end
+
+ desc 'Run all features'
+ task :all => [:ok, :wip]
+ end
+ desc 'Alias for cucumber:ok'
+ task :cucumber => 'cucumber:ok'
+
+ task :default => :cucumber
+
+ task :features => :cucumber do
+ STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
+ end
+
+ # In case we don't have ActiveRecord, append a no-op task that we can depend upon.
+ task 'db:test:prepare' do
+ end
+rescue LoadError
+ desc 'cucumber rake task not available (cucumber not installed)'
+ task :cucumber do
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
+ end
+end
+
+end
View
239 public/index.html
@@ -1,239 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Ruby on Rails: Welcome aboard</title>
- <style type="text/css" media="screen">
- body {
- margin: 0;
- margin-bottom: 25px;
- padding: 0;
- background-color: #f0f0f0;
- font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
- font-size: 13px;
- color: #333;
- }
-
- h1 {
- font-size: 28px;
- color: #000;
- }
-
- a {color: #03c}
- a:hover {
- background-color: #03c;
- color: white;
- text-decoration: none;
- }
-
-
- #page {
- background-color: #f0f0f0;
- width: 750px;
- margin: 0;
- margin-left: auto;
- margin-right: auto;
- }
-
- #content {
- float: left;
- background-color: white;
- border: 3px solid #aaa;
- border-top: none;
- padding: 25px;
- width: 500px;
- }
-
- #sidebar {
- float: right;
- width: 175px;
- }
-
- #footer {
- clear: both;
- }
-
-
- #header, #about, #getting-started {
- padding-left: 75px;
- padding-right: 30px;
- }
-
-
- #header {
- background-image: url("images/rails.png");
- background-repeat: no-repeat;
- background-position: top left;
- height: 64px;
- }
- #header h1, #header h2 {margin: 0}
- #header h2 {
- color: #888;
- font-weight: normal;
- font-size: 16px;
- }
-
-
- #about h3 {
- margin: 0;
- margin-bottom: 10px;
- font-size: 14px;
- }
-
- #about-content {
- background-color: #ffd;
- border: 1px solid #fc0;
- margin-left: -55px;
- margin-right: -10px;
- }
- #about-content table {
- margin-top: 10px;
- margin-bottom: 10px;
- font-size: 11px;
- border-collapse: collapse;
- }
- #about-content td {
- padding: 10px;
- padding-top: 3px;
- padding-bottom: 3px;
- }
- #about-content td.name {color: #555}
- #about-content td.value {color: #000}
-
- #about-content ul {
- padding: 0;
- list-style-type: none;
- }
-
- #about-content.failure {
- background-color: #fcc;
- border: 1px solid #f00;
- }
- #about-content.failure p {
- margin: 0;
- padding: 10px;
- }
-
-
- #getting-started {
- border-top: 1px solid #ccc;
- margin-top: 25px;
- padding-top: 15px;
- }
- #getting-started h1 {
- margin: 0;
- font-size: 20px;
- }
- #getting-started h2 {
- margin: 0;
- font-size: 14px;
- font-weight: normal;
- color: #333;
- margin-bottom: 25px;
- }
- #getting-started ol {
- margin-left: 0;
- padding-left: 0;
- }
- #getting-started li {
- font-size: 18px;
- color: #888;
- margin-bottom: 25px;
- }
- #getting-started li h2 {
- margin: 0;
- font-weight: normal;
- font-size: 18px;
- color: #333;
- }
- #getting-started li p {
- color: #555;
- font-size: 13px;
- }
-
-
- #sidebar ul {
- margin-left: 0;
- padding-left: 0;
- }
- #sidebar ul h3 {
- margin-top: 25px;
- font-size: 16px;
- padding-bottom: 10px;
- border-bottom: 1px solid #ccc;
- }
- #sidebar li {
- list-style-type: none;
- }
- #sidebar ul.links li {
- margin-bottom: 5px;
- }
-
- </style>
- <script type="text/javascript">
- function about() {
- info = document.getElementById('about-content');
- if (window.XMLHttpRequest)
- { xhr = new XMLHttpRequest(); }
- else
- { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
- xhr.open("GET","rails/info/properties",false);
- xhr.send("");
- info.innerHTML = xhr.responseText;
- info.style.display = 'block'
- }
- </script>
- </head>
- <body>
- <div id="page">
- <div id="sidebar">
- <ul id="sidebar-items">
- <li>
- <h3>Browse the documentation</h3>
- <ul class="links">
- <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
- <li><a href="http://stdlib.rubyonrails.org/">Ruby standard library</a></li>
- <li><a href="http://corelib.rubyonrails.org/">Ruby core</a></li>
- <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
- </ul>
- </li>
- </ul>
- </div>
-
- <div id="content">
- <div id="header">
- <h1>Welcome aboard</h1>
- <h2>You&rsquo;re riding Ruby on Rails!</h2>
- </div>
-
- <div id="about">
- <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
- <div id="about-content" style="display: none"></div>
- </div>
-
- <div id="getting-started">
- <h1>Getting started</h1>
- <h2>Here&rsquo;s how to get rolling:</h2>
-
- <ol>
- <li>
- <h2>Use <code>rails generate</code> to create your models and controllers</h2>
- <p>To see all available options, run it without parameters.</p>
- </li>
-
- <li>
- <h2>Set up a default route and remove or rename this file</h2>
- <p>Routes are set up in config/routes.rb.</p>
- </li>
-
- <li>
- <h2>Create your database</h2>
- <p>Run <code>rake db:migrate</code> to create your database. If you're not using SQLite (the default), edit <code>config/database.yml</code> with your username and password.</p>
- </li>
- </ol>
- </div>
- </div>
-
- <div id="footer">&nbsp;</div>
- </div>
- </body>
-</html>
View
10 script/cucumber
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby
+
+vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
+if vendored_cucumber_bin
+ load File.expand_path(vendored_cucumber_bin)
+else
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
+ require 'cucumber'
+ load Cucumber::BINARY
+end
View
115 spec/models/post_spec.rb
@@ -0,0 +1,115 @@
+
+require 'spec_helper'
+
+describe Post do
+
+ before(:each) do
+ @attr = {
+ :title => "Foo Post",
+ :content => "Bar Content"
+ }
+ @post = Post.new(@attr)
+ end
+
+ describe "create post" do
+ it "should create a post with title and content" do
+ @post.should be_valid
+ end
+
+ it "should not create a post without title" do
+ @post.title = nil
+ @post.should_not be_valid
+ end
+
+ it "should not create a post without content" do
+ @post.content = nil
+ @post.should_not be_valid
+ end
+
+ it "should not create a post with blank title" do
+ @post.title = " "
+ @post.should_not be_valid
+ end
+
+ it "should embed many comments" do
+ @post.should embed_many(:comments).with_dependent(:destroy)
+ end
+
+ it "should have one or many authors" do
+ @post.should have_and_belong_to_many(:users)
+ end
+ end
+
+ context "create post validations" do
+
+ describe "#slug" do
+ it "should be generated while saving" do
+ @post.save!
+ @post.slug.should_not be_nil
+ @post.slug.should == "foo-post"
+ end
+
+ it "should truncate unwanted spaces and put - in slug" do
+ @post.title = "Foo Post"
+ @post.save!
+ @post.slug.should == "foo-post"
+ @post.title.should == "Foo Post"
+ end
+
+ it "should replace all special characters with -" do
+ @post.title = "Foo+Post#Test"
+ @post.save!
+ @post.slug.should == "foo-post-test"
+ @post.title.should == "Foo+Post#Test"
+ end
+
+ it "should replace all consecutive occurences of -'s to a single -" do
+ @post.title = "Foo+-Post*#Test"
+ @post.save!
+ @post.slug.should == "foo-post-test"
+ @post.title.should == "Foo+-Post*#Test"
+ end
+
+ it "should not accept duplicates while saving" do
+ @post.save!
+ post1 = Post.new(@attr.merge(:title=>"Foo+Post"))
+ post1.safely.save.should raise_error
+ end
+ end
+
+ describe "#tags" do
+ it "should be nil if not given" do
+ @post.tags.should be_nil
+ end
+
+ it "should have one element if input has one tag" do
+ @post.post_tags = "Ruby"
+ @post.save!
+ @post.tags.should_not be_empty
+ @post.tags.should include("Ruby")
+ @post.tags.size.should == 1
+ end
+
+ it "should have n elements if input has n tags" do
+ @post.post_tags = "Ruby,Rails,Sinatra,Merb"
+ @post.save!
+ @post.tags.should == ["Ruby","Rails","Sinatra","Merb"]
+ end
+ end
+
+ describe "#title" do
+ it "should not accept duplicates" do
+ @post.save!
+ post1 = Post.new(@attr)
+ post1.should_not be_valid
+ end
+ end
+
+ describe "#published_on" do
+ it "should be a valid date time" do
+ @post.save!
+ @post.published_on.should_not be_nil
+ end
+ end
+ end
+end
View
37 spec/spec_helper.rb
@@ -0,0 +1,37 @@
+# This file is copied to spec/ when you run 'rails generate rspec:install'
+ENV["RAILS_ENV"] ||= 'test'
+require File.expand_path("../../config/environment", __FILE__)
+require 'rspec/rails'
+
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+
+RSpec.configure do |config|
+ # == Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+ config.mock_with :rspec
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ #config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ #config.use_transactional_fixtures = true
+
+ require 'database_cleaner'
+ config.before(:suite) do
+ DatabaseCleaner.strategy = :truncation
+ DatabaseCleaner.orm = "mongoid"
+ end
+
+ config.before(:each) do
+ DatabaseCleaner.clean
+ end
+end
View
3 spec/support/devise.rb
@@ -0,0 +1,3 @@
+RSpec.configure do |config|
+ config.include Devise::TestHelpers, :type => :controller
+end
View
4 spec/support/mongoid.rb
@@ -0,0 +1,4 @@
+
+RSpec.configure do |config|
+ config.include Mongoid::Matchers
+end
View
13 test/fixtures/comments.yml
@@ -1,13 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-one:
- author:
- email:
- url:
- content: MyText
-
-two:
- author:
- email:
- url:
- content: MyText
View
9 test/fixtures/posts.yml
@@ -1,9 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-one:
- title: MyString
- content: MyText
-
-two:
- title: MyString
- content: MyText
View
11 test/fixtures/users.yml
@@ -1,11 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-# This model initially had no columns defined. If you add columns to the
-# model remove the '{}' from the fixture names and add the columns immediately
-# below each fixture, per the syntax in the comments below
-#
-one: {}
-# column: value
-#
-two: {}
-# column: value
View
8 test/functional/comments_controller_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class CommentsControllerTest < ActionController::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
49 test/functional/posts_controller_test.rb
@@ -1,49 +0,0 @@
-require 'test_helper'
-
-class PostsControllerTest < ActionController::TestCase
- setup do
- @post = posts(:one)
- end
-
- test "should get index" do
- get :index
- assert_response :success
- assert_not_nil assigns(:posts)
- end
-
- test "should get new" do
- get :new
- assert_response :success
- end
-
- test "should create post" do
- assert_difference('Post.count') do
- post :create, :post => @post.attributes
- end
-
- assert_redirected_to post_path(assigns(:post))
- end
-
- test "should show post" do
- get :show, :id => @post.to_param
- assert_response :success
- end
-
- test "should get edit" do
- get :edit, :id => @post.to_param
- assert_response :success
- end
-
- test "should update post" do
- put :update, :id => @post.to_param, :post => @post.attributes
- assert_redirected_to post_path(assigns(:post))
- end
-
- test "should destroy post" do
- assert_difference('Post.count', -1) do
- delete :destroy, :id => @post.to_param
- end
-
- assert_redirected_to posts_path
- end
-end
View
9 test/performance/browsing_test.rb
@@ -1,9 +0,0 @@
-require 'test_helper'
-require 'rails/performance_test_help'
-
-# Profiling results for each test method are written to tmp/performance.
-class BrowsingTest < ActionDispatch::PerformanceTest
- def test_homepage
- get '/'
- end
-end
View
7 test/test_helper.rb
@@ -1,7 +0,0 @@
-ENV["RAILS_ENV"] = "test"
-require File.expand_path('../../config/environment', __FILE__)
-require 'rails/test_help'
-
-class ActiveSupport::TestCase
- # Add more helper methods to be used by all tests here...
-end
View
8 test/unit/comment_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class CommentTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
4 test/unit/helpers/comments_helper_test.rb
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class CommentsHelperTest < ActionView::TestCase
-end
View
4 test/unit/helpers/posts_helper_test.rb
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class PostsHelperTest < ActionView::TestCase
-end
View
8 test/unit/post_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class PostTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
8 test/unit/user_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class UserTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end

0 comments on commit a14e73c

Please sign in to comment.