Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First pass at Project class

  • Loading branch information...
commit d42ee28d02dcafa74a9fcf1705afda13d10cbbb3 1 parent d37df7a
@leereilly authored
View
5 Gemfile
@@ -28,3 +28,8 @@ gem 'sqlite3-ruby', :require => 'sqlite3'
# group :development, :test do
# gem 'webrat'
# end
+
+group :test do
+ gem 'factory_girl', '1.3.2'
+ gem 'faker', '0.3.1'
+end
View
2  app/controllers/projects_controller.rb
@@ -0,0 +1,2 @@
+class ProjectsController < ApplicationController
+end
View
2  app/helpers/projects_helper.rb
@@ -0,0 +1,2 @@
+module ProjectsHelper
+end
View
4 app/models/project.rb
@@ -0,0 +1,4 @@
+class Project < ActiveRecord::Base
+ validates_presence_of :name, :slug
+ validates_uniqueness_of :slug
+end
View
2  config/routes.rb
@@ -1,4 +1,6 @@
RiskRegisterOnRails::Application.routes.draw do
+ resources :projects
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
14 db/migrate/20101220025003_create_projects.rb
@@ -0,0 +1,14 @@
+class CreateProjects < ActiveRecord::Migration
+ def self.up
+ create_table :projects do |t|
+ t.string :slug
+ t.string :name
+ t.text :description
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :projects
+ end
+end
View
BIN  public/images/risk.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
9 test/factories/project.rb
@@ -0,0 +1,9 @@
+Factory.sequence :slug do |n|
+ "SLUG-#{n}"
+end
+
+Factory.define :project, :class => 'project' do |p|
+ p.slug {Factory.next :slug}
+ p.name {Faker::Company.catch_phrase}
+ p.description {Faker::Company.catch_phrase}
+ end
View
8 test/functional/projects_controller_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class ProjectsControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
View
5 test/test_helper.rb
@@ -2,6 +2,11 @@
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
+require 'factory_girl'
+Dir.glob(File.dirname(__FILE__) + "/factories/*").each do |factory|
+ require factory
+end
+
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
View
4 test/unit/helpers/projects_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ProjectsHelperTest < ActionView::TestCase
+end
View
21 test/unit/project_test.rb
@@ -0,0 +1,21 @@
+require 'test_helper'
+
+class ProjectTest < ActiveSupport::TestCase
+
+ test "project slugs should be unique" do
+ project1 = Factory.create(:project)
+ project2 = Factory.create(:project)
+ project1.slug = project2.slug
+ assert_equal false, project1.valid?
+ end
+
+ test "should not save project without name and slug" do
+ project = Project.new
+ assert_equal false, project.valid?
+ project.name = 'Project name'
+ assert_equal false, project.valid?
+ project.slug = 'Project slug'
+ assert_equal true, project.valid?
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.