Initial import
This commit is contained in:
25
vendor/plugins/shoulda/test/rails_root/app/controllers/application.rb
vendored
Normal file
25
vendor/plugins/shoulda/test/rails_root/app/controllers/application.rb
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
# Filters added to this controller apply to all controllers in the application.
|
||||
# Likewise, all the methods added will be available for all controllers.
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
# Pick a unique cookie name to distinguish our session data from others'
|
||||
session :session_key => '_rails_root_session_id'
|
||||
|
||||
def ensure_logged_in
|
||||
unless session[:logged_in]
|
||||
respond_to do |accepts|
|
||||
accepts.html do
|
||||
flash[:error] = 'What do you think you\'re doing?'
|
||||
redirect_to '/'
|
||||
end
|
||||
accepts.xml do
|
||||
headers["Status"] = "Unauthorized"
|
||||
headers["WWW-Authenticate"] = %(Basic realm="Web Password")
|
||||
render :text => "Couldn't authenticate you", :status => '401 Unauthorized'
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
78
vendor/plugins/shoulda/test/rails_root/app/controllers/posts_controller.rb
vendored
Normal file
78
vendor/plugins/shoulda/test/rails_root/app/controllers/posts_controller.rb
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
class PostsController < ApplicationController
|
||||
before_filter :ensure_logged_in
|
||||
before_filter :load_user
|
||||
|
||||
def index
|
||||
@posts = @user.posts
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.rhtml
|
||||
format.xml { render :xml => @posts.to_xml }
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@post = @user.posts.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.rhtml
|
||||
format.xml { render :xml => @post.to_xml }
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@post = @user.posts.build
|
||||
end
|
||||
|
||||
def edit
|
||||
@post = @user.posts.find(params[:id])
|
||||
end
|
||||
|
||||
def create
|
||||
@post = @user.posts.build(params[:post])
|
||||
|
||||
respond_to do |format|
|
||||
if @post.save
|
||||
flash[:notice] = 'Post was successfully created.'
|
||||
format.html { redirect_to post_url(@post.user, @post) }
|
||||
format.xml { head :created, :location => post_url(@post.user, @post) }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
format.xml { render :xml => @post.errors.to_xml }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@post = @user.posts.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @post.update_attributes(params[:post])
|
||||
flash[:notice] = 'Post was successfully updated.'
|
||||
format.html { redirect_to post_url(@post.user, @post) }
|
||||
format.xml { head :ok }
|
||||
else
|
||||
format.html { render :action => "edit" }
|
||||
format.xml { render :xml => @post.errors.to_xml }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@post = @user.posts.find(params[:id])
|
||||
@post.destroy
|
||||
|
||||
flash[:notice] = "Post was removed"
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to posts_url(@post.user) }
|
||||
format.xml { head :ok }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_user
|
||||
@user = User.find(params[:user_id])
|
||||
end
|
||||
end
|
||||
81
vendor/plugins/shoulda/test/rails_root/app/controllers/users_controller.rb
vendored
Normal file
81
vendor/plugins/shoulda/test/rails_root/app/controllers/users_controller.rb
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
class UsersController < ApplicationController
|
||||
# GET /users
|
||||
# GET /users.xml
|
||||
def index
|
||||
@users = User.find(:all)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.rhtml
|
||||
format.xml { render :xml => @users.to_xml }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /users/1
|
||||
# GET /users/1.xml
|
||||
def show
|
||||
@user = User.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.rhtml
|
||||
format.xml { render :xml => @user.to_xml }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /users/new
|
||||
def new
|
||||
@user = User.new
|
||||
end
|
||||
|
||||
# GET /users/1;edit
|
||||
def edit
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
|
||||
# POST /users
|
||||
# POST /users.xml
|
||||
def create
|
||||
@user = User.new(params[:user])
|
||||
|
||||
respond_to do |format|
|
||||
if @user.save
|
||||
flash[:notice] = 'User was successfully created.'
|
||||
format.html { redirect_to user_url(@user) }
|
||||
format.xml { head :created, :location => user_url(@user) }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
format.xml { render :xml => @user.errors.to_xml }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /users/1
|
||||
# PUT /users/1.xml
|
||||
def update
|
||||
@user = User.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @user.update_attributes(params[:user])
|
||||
flash[:notice] = 'User was successfully updated.'
|
||||
format.html { redirect_to user_url(@user) }
|
||||
format.xml { head :ok }
|
||||
else
|
||||
format.html { render :action => "edit" }
|
||||
format.xml { render :xml => @user.errors.to_xml }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /users/1
|
||||
# DELETE /users/1.xml
|
||||
def destroy
|
||||
@user = User.find(params[:id])
|
||||
@user.destroy
|
||||
|
||||
flash[:notice] = "User was removed"
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to users_url }
|
||||
format.xml { head :ok }
|
||||
end
|
||||
end
|
||||
end
|
||||
3
vendor/plugins/shoulda/test/rails_root/app/helpers/application_helper.rb
vendored
Normal file
3
vendor/plugins/shoulda/test/rails_root/app/helpers/application_helper.rb
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# Methods added to this helper will be available to all templates in the application.
|
||||
module ApplicationHelper
|
||||
end
|
||||
2
vendor/plugins/shoulda/test/rails_root/app/helpers/posts_helper.rb
vendored
Normal file
2
vendor/plugins/shoulda/test/rails_root/app/helpers/posts_helper.rb
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
module PostsHelper
|
||||
end
|
||||
2
vendor/plugins/shoulda/test/rails_root/app/helpers/users_helper.rb
vendored
Normal file
2
vendor/plugins/shoulda/test/rails_root/app/helpers/users_helper.rb
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
module UsersHelper
|
||||
end
|
||||
3
vendor/plugins/shoulda/test/rails_root/app/models/dog.rb
vendored
Normal file
3
vendor/plugins/shoulda/test/rails_root/app/models/dog.rb
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
class Dog < ActiveRecord::Base
|
||||
belongs_to :user, :foreign_key => :owner_id
|
||||
end
|
||||
11
vendor/plugins/shoulda/test/rails_root/app/models/post.rb
vendored
Normal file
11
vendor/plugins/shoulda/test/rails_root/app/models/post.rb
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
class Post < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :owner, :foreign_key => :user_id, :class_name => 'User'
|
||||
has_many :taggings
|
||||
has_many :tags, :through => :taggings
|
||||
|
||||
validates_uniqueness_of :title
|
||||
validates_presence_of :title
|
||||
validates_presence_of :body, :message => 'Seriously... wtf'
|
||||
validates_numericality_of :user_id
|
||||
end
|
||||
4
vendor/plugins/shoulda/test/rails_root/app/models/tag.rb
vendored
Normal file
4
vendor/plugins/shoulda/test/rails_root/app/models/tag.rb
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
class Tag < ActiveRecord::Base
|
||||
has_many :taggings
|
||||
has_many :posts, :through => :taggings
|
||||
end
|
||||
4
vendor/plugins/shoulda/test/rails_root/app/models/tagging.rb
vendored
Normal file
4
vendor/plugins/shoulda/test/rails_root/app/models/tagging.rb
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
class Tagging < ActiveRecord::Base
|
||||
belongs_to :post
|
||||
belongs_to :tag
|
||||
end
|
||||
9
vendor/plugins/shoulda/test/rails_root/app/models/user.rb
vendored
Normal file
9
vendor/plugins/shoulda/test/rails_root/app/models/user.rb
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
class User < ActiveRecord::Base
|
||||
has_many :posts
|
||||
has_many :dogs, :foreign_key => :owner_id
|
||||
|
||||
attr_protected :password
|
||||
validates_format_of :email, :with => /\w*@\w*.com/
|
||||
validates_length_of :email, :in => 1..100
|
||||
validates_inclusion_of :age, :in => 1..100
|
||||
end
|
||||
17
vendor/plugins/shoulda/test/rails_root/app/views/layouts/posts.rhtml
vendored
Normal file
17
vendor/plugins/shoulda/test/rails_root/app/views/layouts/posts.rhtml
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
||||
<title>Posts: <%= controller.action_name %></title>
|
||||
<%= stylesheet_link_tag 'scaffold' %>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p style="color: green"><%= flash[:notice] %></p>
|
||||
|
||||
<%= yield %>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
17
vendor/plugins/shoulda/test/rails_root/app/views/layouts/users.rhtml
vendored
Normal file
17
vendor/plugins/shoulda/test/rails_root/app/views/layouts/users.rhtml
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
||||
<title>Users: <%= controller.action_name %></title>
|
||||
<%= stylesheet_link_tag 'scaffold' %>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p style="color: green"><%= flash[:notice] %></p>
|
||||
|
||||
<%= yield %>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
27
vendor/plugins/shoulda/test/rails_root/app/views/posts/edit.rhtml
vendored
Normal file
27
vendor/plugins/shoulda/test/rails_root/app/views/posts/edit.rhtml
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<h1>Editing post</h1>
|
||||
|
||||
<%= error_messages_for :post %>
|
||||
|
||||
<% form_for(:post, :url => post_path(@post.user, @post), :html => { :method => :put }) do |f| %>
|
||||
<p>
|
||||
<b>User</b><br />
|
||||
<%= f.text_field :user_id %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Title</b><br />
|
||||
<%= f.text_field :title %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Body</b><br />
|
||||
<%= f.text_area :body %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= submit_tag "Update" %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'Show', post_path(@post.user, @post) %> |
|
||||
<%= link_to 'Back', posts_path(@post.user) %>
|
||||
24
vendor/plugins/shoulda/test/rails_root/app/views/posts/index.rhtml
vendored
Normal file
24
vendor/plugins/shoulda/test/rails_root/app/views/posts/index.rhtml
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<h1>Listing posts</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>User</th>
|
||||
<th>Title</th>
|
||||
<th>Body</th>
|
||||
</tr>
|
||||
|
||||
<% for post in @posts %>
|
||||
<tr>
|
||||
<td><%=h post.user_id %></td>
|
||||
<td><%=h post.title %></td>
|
||||
<td><%=h post.body %></td>
|
||||
<td><%= link_to 'Show', post_path(post.user, post) %></td>
|
||||
<td><%= link_to 'Edit', edit_post_path(post.user, post) %></td>
|
||||
<td><%= link_to 'Destroy', post_path(post.user, post), :confirm => 'Are you sure?', :method => :delete %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<%= link_to 'New post', new_post_path(post.user) %>
|
||||
26
vendor/plugins/shoulda/test/rails_root/app/views/posts/new.rhtml
vendored
Normal file
26
vendor/plugins/shoulda/test/rails_root/app/views/posts/new.rhtml
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<h1>New post</h1>
|
||||
|
||||
<%= error_messages_for :post %>
|
||||
|
||||
<% form_for(:post, :url => posts_path(@user)) do |f| %>
|
||||
<p>
|
||||
<b>User</b><br />
|
||||
<%= f.text_field :user_id %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Title</b><br />
|
||||
<%= f.text_field :title %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Body</b><br />
|
||||
<%= f.text_area :body %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= submit_tag "Create" %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'Back', posts_path(@user) %>
|
||||
18
vendor/plugins/shoulda/test/rails_root/app/views/posts/show.rhtml
vendored
Normal file
18
vendor/plugins/shoulda/test/rails_root/app/views/posts/show.rhtml
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<p>
|
||||
<b>User:</b>
|
||||
<%=h @post.user_id %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Title:</b>
|
||||
<%=h @post.title %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Body:</b>
|
||||
<%=h @post.body %>
|
||||
</p>
|
||||
|
||||
|
||||
<%= link_to 'Edit', edit_post_path(@post.user, @post) %> |
|
||||
<%= link_to 'Back', posts_path(@post.user) %>
|
||||
22
vendor/plugins/shoulda/test/rails_root/app/views/users/edit.rhtml
vendored
Normal file
22
vendor/plugins/shoulda/test/rails_root/app/views/users/edit.rhtml
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<h1>Editing user</h1>
|
||||
|
||||
<%= error_messages_for :user %>
|
||||
|
||||
<% form_for(:user, :url => user_path(@user), :html => { :method => :put }) do |f| %>
|
||||
<p>
|
||||
<b>Email</b><br />
|
||||
<%= f.text_field :email %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Age</b><br />
|
||||
<%= f.text_field :age %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= submit_tag "Update" %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'Show', user_path(@user) %> |
|
||||
<%= link_to 'Back', users_path %>
|
||||
22
vendor/plugins/shoulda/test/rails_root/app/views/users/index.rhtml
vendored
Normal file
22
vendor/plugins/shoulda/test/rails_root/app/views/users/index.rhtml
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<h1>Listing users</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Email</th>
|
||||
<th>Age</th>
|
||||
</tr>
|
||||
|
||||
<% for user in @users %>
|
||||
<tr>
|
||||
<td><%=h user.email %></td>
|
||||
<td><%=h user.age %></td>
|
||||
<td><%= link_to 'Show', user_path(user) %></td>
|
||||
<td><%= link_to 'Edit', edit_user_path(user) %></td>
|
||||
<td><%= link_to 'Destroy', user_path(user), :confirm => 'Are you sure?', :method => :delete %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<%= link_to 'New user', new_user_path %>
|
||||
21
vendor/plugins/shoulda/test/rails_root/app/views/users/new.rhtml
vendored
Normal file
21
vendor/plugins/shoulda/test/rails_root/app/views/users/new.rhtml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<h1>New user</h1>
|
||||
|
||||
<%= error_messages_for :user %>
|
||||
|
||||
<% form_for(:user, :url => users_path) do |f| %>
|
||||
<p>
|
||||
<b>Email</b><br />
|
||||
<%= f.text_field :email %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Age</b><br />
|
||||
<%= f.text_field :age %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= submit_tag "Create" %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'Back', users_path %>
|
||||
13
vendor/plugins/shoulda/test/rails_root/app/views/users/show.rhtml
vendored
Normal file
13
vendor/plugins/shoulda/test/rails_root/app/views/users/show.rhtml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<p>
|
||||
<b>Email:</b>
|
||||
<%=h @user.email %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Age:</b>
|
||||
<%=h @user.age %>
|
||||
</p>
|
||||
|
||||
|
||||
<%= link_to 'Edit', edit_user_path(@user) %> |
|
||||
<%= link_to 'Back', users_path %>
|
||||
Reference in New Issue
Block a user