Skip to content

Commit

Permalink
Start on controllers and views. Use RSpec instead of Test::Unit
Browse files Browse the repository at this point in the history
  • Loading branch information
zuhao committed Jun 24, 2012
1 parent 4ee1e63 commit 911ca1b
Show file tree
Hide file tree
Showing 39 changed files with 260 additions and 287 deletions.
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--colour
10 changes: 10 additions & 0 deletions Gemfile
Expand Up @@ -19,6 +19,16 @@ gem 'haml-rails'

gem 'haml'
gem 'execjs'

group :test, :development do
gem 'rspec-rails', '~> 2.0'
gem 'capybara'
end

group :production do

end

# gem 'grit'
# gem 'git' # ruby-git seems to have better support on remote repo than grit

Expand Down
38 changes: 38 additions & 0 deletions Gemfile.lock
Expand Up @@ -28,18 +28,30 @@ GEM
activesupport (3.2.3)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.2.8)
arel (3.0.2)
builder (3.0.0)
capybara (1.1.2)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
childprocess (0.3.2)
ffi (~> 1.0.6)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.3.1)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
ffi (1.0.11)
haml (3.1.6)
haml-rails (0.3.4)
actionpack (~> 3.0)
Expand All @@ -54,12 +66,15 @@ GEM
thor (~> 0.14)
json (1.6.6)
libv8 (3.3.10.4)
libwebsocket (0.1.3)
addressable
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.18)
multi_json (1.3.2)
nokogiri (1.5.5)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
Expand All @@ -86,11 +101,30 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
rspec (2.10.0)
rspec-core (~> 2.10.0)
rspec-expectations (~> 2.10.0)
rspec-mocks (~> 2.10.0)
rspec-core (2.10.1)
rspec-expectations (2.10.0)
diff-lcs (~> 1.1.3)
rspec-mocks (2.10.1)
rspec-rails (2.10.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.10.0)
rubyzip (0.9.9)
sass (3.1.16)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
selenium-webdriver (2.24.0)
childprocess (>= 0.2.5)
libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
Expand All @@ -107,17 +141,21 @@ GEM
uglifier (1.2.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
xpath (0.1.4)
nokogiri (~> 1.3)

PLATFORMS
ruby

DEPENDENCIES
capybara
coffee-rails (~> 3.2.1)
execjs
haml
haml-rails
jquery-rails
rails (= 3.2.3)
rspec-rails (~> 2.0)
sass-rails (~> 3.2.3)
sqlite3
therubyracer
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/gemcomments.js.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/javascripts/home.js.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/javascripts/rpmcomments.js.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/gemcomments.css.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the gemcomments controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/home.css.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the home controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/rpmcomments.css.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the rpmcomments controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
6 changes: 4 additions & 2 deletions app/controllers/fedorarpms_controller.rb
@@ -1,12 +1,14 @@
class FedorarpmsController < ApplicationController

def all
def index
@page_title = 'All Rpm'
# @rpms = FedoraRpm.all
@rpms = FedoraRpm.limit(100)
end

def show
@rpm = FedoraRpm.find_by_id(params[:id])
id = params[:id]
@rpm = FedoraRpm.find_by_id(id)
@page_title = @rpm.name
end

Expand Down
12 changes: 12 additions & 0 deletions app/controllers/gemcomments_controller.rb
@@ -0,0 +1,12 @@
class GemcommentsController < ApplicationController
def index
@gem = RubyGem.find_by_id(params[:id])
end

def create
@gem = RubyGem.find_by_id(params[:id])
@comment = @gem.gem_comments.build(params[:gem_comment])
@comment.save!
end

end
5 changes: 5 additions & 0 deletions app/controllers/home_controller.rb
@@ -0,0 +1,5 @@
class HomeController < ApplicationController
def show
@page_title = 'Welcome'
end
end
2 changes: 2 additions & 0 deletions app/controllers/rpmcomments_controller.rb
@@ -0,0 +1,2 @@
class RpmcommentsController < ApplicationController
end
6 changes: 4 additions & 2 deletions app/controllers/rubygems_controller.rb
@@ -1,12 +1,14 @@
class RubygemsController < ApplicationController

def all
def index
@page_title = 'All Gems'
# @gems = RubyGem.all
@gems = RubyGem.limit(100)
end

def show
@gem = RubyGem.find_by_id(params[:id])
@id = params[:id]
@gem = RubyGem.find_by_id(@id, :include => :gem_comments)
@page_title = @gem.name
end

Expand Down
2 changes: 2 additions & 0 deletions app/helpers/gemcomments_helper.rb
@@ -0,0 +1,2 @@
module GemcommentsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/home_helper.rb
@@ -0,0 +1,2 @@
module HomeHelper
end
2 changes: 2 additions & 0 deletions app/helpers/rpmcomments_helper.rb
@@ -0,0 +1,2 @@
module RpmcommentsHelper
end
2 changes: 1 addition & 1 deletion app/models/fedora_rpm.rb
@@ -1,7 +1,7 @@
class FedoraRpm < ActiveRecord::Base

belongs_to :ruby_gem
has_many :rpm_comment, :dependent => :destroy, :order => 'created_at desc'
has_many :rpm_comments, :dependent => :destroy, :order => 'created_at desc'
has_many :working_comments, :class_name => 'RpmComment', :conditions => {:works_for_me => true}
has_many :failure_comments, :class_name => 'RpmComment', :conditions => {:works_for_me => false}
scope :popular, :order => 'rpm_comments_count desc'
Expand Down
2 changes: 1 addition & 1 deletion app/models/ruby_gem.rb
@@ -1,7 +1,7 @@
class RubyGem < ActiveRecord::Base

has_one :fedora_rpm, :dependent => :destroy
has_many :gem_comment, :dependent => :destroy, :order => 'created_at desc'
has_many :gem_comments, :dependent => :destroy, :order => 'created_at desc'
scope :popular, :order => 'gem_comments_count desc'

def self.new_from_gem_tuple(gem_tuple)
Expand Down
11 changes: 0 additions & 11 deletions app/views/fedorarpms/all.html.haml

This file was deleted.

15 changes: 15 additions & 0 deletions app/views/fedorarpms/index.html.haml
@@ -0,0 +1,15 @@
%h2 All Fedora Rpms

%table
%thead
%tr
%th Name
%th Version
%th Gem

%tbody
- @rpms.each do |rpm|
%tr
%td= link_to rpm.name, fedorarpm_path(rpm.id)
%td= rpm.version
%td= link_to 'View', rubygem_path(rpm.ruby_gem.id) if rpm.ruby_gem != nil
9 changes: 5 additions & 4 deletions app/views/fedorarpms/show.html.haml
@@ -1,7 +1,8 @@
%h1= @rpm.name
%h2= @rpm.name
%p= link_to 'Homepage', @rpm.homepage
/%p= link_to 'Git', @rpm.git_url
%p Description
/%p= "#{@rpm.description}"
%p= button_to "Back to all rpms", fedorarpms_path, :method => :all
%p= button_to "Back to all gems", rubygems_path, :method => :all
%p
= link_to "Back to rpm list", fedorarpms_path, :method => :all
= link_to "Back to gem list", rubygems_path, :method => :all
2 changes: 2 additions & 0 deletions app/views/gemcomments/_comments.html.haml
@@ -0,0 +1,2 @@
%div
%p= gemcomment.name
4 changes: 4 additions & 0 deletions app/views/gemcomments/_new_comment.html.haml
@@ -0,0 +1,4 @@
%h2 Add new comment
- form_tag rubygem_path(params[:id]), :method => :post do
label :gem_comment, :name, 'Name'
text_field :gem_comment, :name
10 changes: 10 additions & 0 deletions app/views/home/show.html.haml
@@ -0,0 +1,10 @@
!!!
%html
%head
%title Is It Fedora Ruby

%body
%h1 Is It Fedora Ruby

%p= link_to 'Ruby gems', rubygems_path
%p= link_to 'Fedora rpms', fedorarpms_path
9 changes: 4 additions & 5 deletions app/views/layouts/application.html.haml
Expand Up @@ -2,10 +2,9 @@
%html
%head
%title= "isitfedoraruby.com - #{@page_title}"

/ <%= stylesheet_link_tag "application", :media => "all" %>
/ <%= javascript_include_tag "application" %>
/ <%= csrf_meta_tags %>
= stylesheet_link_tag "application"
= javascript_include_tag "application"
= csrf_meta_tags

%body
%div= yield
= yield
11 changes: 0 additions & 11 deletions app/views/rubygems/all.html.haml

This file was deleted.

15 changes: 15 additions & 0 deletions app/views/rubygems/index.html.haml
@@ -0,0 +1,15 @@
%h2 All Ruby Gems

%table
%thead
%tr
%th Name
%th Version
%th Rpm

%tbody
- @gems.each do |gem|
%tr
%td= link_to gem.name, rubygem_path(gem.id)
%td= gem.version
%td= link_to 'View', fedorarpm_path(gem.fedora_rpm.id) if gem.fedora_rpm != nil
34 changes: 30 additions & 4 deletions app/views/rubygems/show.html.haml
@@ -1,7 +1,33 @@
%h1= @gem.name
%h2= @gem.name
%p= link_to 'Homepage', @gem.homepage
%p Description:
%p= "#{@gem.description}"
%p= @gem.description

%p= button_to "Back to all gems", rubygems_path, :method => :all
%p= button_to "Back to all rpms", fedorarpms_path, :method => :all
%p
= link_to "Back to gem list", rubygems_path, :method => :all
= link_to "Back to rpm list", fedorarpms_path, :method => :all

%h3 Comments
- @gem.gem_comments.each do |comment|
%p Name: #{comment.name}
%p Email: #{comment.email}
%p Comment: #{comment.text}

%h3 Add new comment
= form_for :gem_comment do |f|
%p
= f.label :name, 'Name'
= f.text_field :name
%p
= f.label :email, 'Email'
= f.text_field :email
%p= f.label :text, 'Comment'
%p= f.text_area :text

= f.submit




/= render :partial => 'gemcomments/comments', :collection => @gem.gem_comments
/= render :partial => 'gemcomments/new_comment', :locals => {:rubygem => @gem}
13 changes: 8 additions & 5 deletions config/routes.rb
@@ -1,12 +1,15 @@
Isitfedoraruby::Application.routes.draw do

match 'rubygems/' => 'rubygems#all'
match 'rubygems/all' => 'rubygems#all'
match '/' => 'home#show'
post 'rubygems/:id', :controller => 'gemcomments', :action => 'create'

match 'rubygems/' => 'rubygems#index'
match 'rubygems/all' => 'rubygems#index'
match 'rubygems/:id' => 'rubygems#show'
match 'rubygems/:id/show' => 'rubygems#show'
match 'fedorarpms/' => 'fedorarpms#all'
match 'fedorarpms/all' => 'fedorarpms#all'

match 'fedorarpms/' => 'fedorarpms#index'
match 'fedorarpms/all' => 'fedorarpms#index'
match 'fedorarpms/:id' => 'fedorarpms#show'
match 'fedorarpms/:id/show' => 'fedorarpms#show'

Expand Down
Binary file modified db/development.sqlite3
Binary file not shown.

0 comments on commit 911ca1b

Please sign in to comment.