Skip to content

Commit

Permalink
command and multple view changes
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Sep 13, 2009
1 parent 8abafae commit cc721ab
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/controllers/commands_controller.rb
@@ -0,0 +1,2 @@
class CommandsController < RestfulController
end
2 changes: 0 additions & 2 deletions app/controllers/home_controller.rb

This file was deleted.

14 changes: 13 additions & 1 deletion app/helpers/application_helper.rb
@@ -1,2 +1,14 @@
module ApplicationHelper
end
def title
return @title if @title
if @current_object
if @current_object.new_record?
"New #{current_model}"
else
@current_object.to_s
end
else
current_model.to_s.pluralize
end
end
end
4 changes: 4 additions & 0 deletions app/models/command.rb
@@ -0,0 +1,4 @@
class Command < ActiveRecord::Base
validates_uniqueness_of :name, :case_sensitive => false
validates_presence_of :name, :description
end
4 changes: 3 additions & 1 deletion app/models/user.rb
Expand Up @@ -18,6 +18,7 @@ def can_create?(object)
return true if admin?
case object
when User then anonymouse?
when Command then false
else raise "NOT SUPPORTED"
end
end
Expand All @@ -26,14 +27,15 @@ def can_write?(object)
return true if admin?
case object
when User then object == self
when Command then false
else raise "NOT SUPPORTED"
end
end

def can_read?(object)
return true if admin?
case object
when User then true
when User, Command then true
else raise "NOT SUPPORTED"
end
end
Expand Down
3 changes: 3 additions & 0 deletions app/views/commands/_command.erb
@@ -0,0 +1,3 @@
<h2><%= command.name %></h2>
<%= command.description %> <br />
<%= command.mac_only? ? "Mac only" : "" %>
1 change: 1 addition & 0 deletions app/views/commands/index.erb
@@ -0,0 +1 @@
<% render :collection => @commands %>
1 change: 0 additions & 1 deletion app/views/home/index.erb

This file was deleted.

1 change: 1 addition & 0 deletions app/views/layouts/_menu.erb
@@ -0,0 +1 @@
<%= link_to "CmdLiner fancy logo", root_path %>
8 changes: 6 additions & 2 deletions app/views/layouts/application.erb
@@ -1,16 +1,20 @@
<html>
<head>
<title>CMDLiner</title>
<title><%=title%> | CmdLiner.com</title>
<link rel="shortcut icon" href="favicon.ico" >
<%= css_tag 'reset' %>
</head>
<body>
<div>
<%= render 'layouts/user' %>
<div>
<%= render 'layouts/menu' %>
<%= render 'layouts/user' %>
</div>
<%= render 'layouts/flash' %>
</div>

<div>
<h1><%=title%></h1>
<%= yield %>
</div>
</body>
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
@@ -1,6 +1,7 @@
ActionController::Routing::Routes.draw do |map|
map.root :controller => 'home'
map.root :controller => :commands
map.login '/login', :controller => "users", :action => "new"

map.resources :users
map.resources :commands, :only=>[:index, :show]
end
17 changes: 17 additions & 0 deletions db/migrate/20090913103817_create_commands.rb
@@ -0,0 +1,17 @@
class CreateCommands < ActiveRecord::Migration
def self.up
create_table :commands do |t|
t.string :name, :null=>false
t.text :description, :null=>false
t.boolean :mac_only, :default=>false, :null=>false
t.timestamps
end

# enforce uniqueness
add_index :commands, :name, :unique => true
end

def self.down
drop_table :commands
end
end
12 changes: 11 additions & 1 deletion db/schema.rb
Expand Up @@ -9,7 +9,17 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20090910191750) do
ActiveRecord::Schema.define(:version => 20090913103817) do

create_table "commands", :force => true do |t|
t.string "name", :null => false
t.text "description", :null => false
t.boolean "mac_only", :default => false, :null => false
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "commands", ["name"], :name => "index_commands_on_name", :unique => true

create_table "users", :force => true do |t|
t.string "name", :null => false
Expand Down
5 changes: 5 additions & 0 deletions spec/factories.rb
Expand Up @@ -9,4 +9,9 @@
Factory.define(:user) do |f|
f.identifier { Factory.next(:identifier) }
f.name { Factory.next(:name) }
end

Factory.define(:command) do |f|
f.name 'ls'
f.description 'show files n stuff'
end
32 changes: 32 additions & 0 deletions spec/helpers/application_helper_spec.rb
@@ -0,0 +1,32 @@
require 'spec/spec_helper'

describe ApplicationHelper do
include ApplicationHelper

describe :title do
before do
stub!(:current_model).and_return User
end

it "fetches the title from @title" do
@title = 'YEP'
title.should == @title
end

it "gets the title from current_object" do
user = Factory(:user)
@current_object = user
title.should == user.to_s
end

it "gets the title from new objects" do
user = Factory.build(:user)
@current_object = user
title.should == "New User"
end

it "gets the title from current_model" do
title.should == 'Users'
end
end
end
10 changes: 10 additions & 0 deletions spec/models/user_spec.rb
Expand Up @@ -13,6 +13,16 @@
behaves_like_owner_changeable(user)
end

it "Command" do
behaves_like_static(Factory(:command))
end

def behaves_like_static(item)
check_can(:read, true, true, true, item)
check_can(:write, false, false, false, item)
check_can(:create, false, false, false, item)
end

def behaves_like_owner_changeable(item)
check_can(:read, true, true, true, item)
check_can(:write, true, false, false, item)
Expand Down

0 comments on commit cc721ab

Please sign in to comment.