Permalink
Browse files

Start on controllers and views. Use RSpec instead of Test::Unit

  • Loading branch information...
1 parent 4ee1e63 commit 911ca1b7788b78a0eaffb5121a3862b896b76559 @zuhao committed Jun 24, 2012
Showing with 260 additions and 287 deletions.
  1. +1 −0 .rspec
  2. +10 −0 Gemfile
  3. +38 −0 Gemfile.lock
  4. +3 −0 app/assets/javascripts/gemcomments.js.coffee
  5. +3 −0 app/assets/javascripts/home.js.coffee
  6. +3 −0 app/assets/javascripts/rpmcomments.js.coffee
  7. +3 −0 app/assets/stylesheets/gemcomments.css.scss
  8. +3 −0 app/assets/stylesheets/home.css.scss
  9. +3 −0 app/assets/stylesheets/rpmcomments.css.scss
  10. +4 −2 app/controllers/fedorarpms_controller.rb
  11. +12 −0 app/controllers/gemcomments_controller.rb
  12. +5 −0 app/controllers/home_controller.rb
  13. +2 −0 app/controllers/rpmcomments_controller.rb
  14. +4 −2 app/controllers/rubygems_controller.rb
  15. +2 −0 app/helpers/gemcomments_helper.rb
  16. +2 −0 app/helpers/home_helper.rb
  17. +2 −0 app/helpers/rpmcomments_helper.rb
  18. +1 −1 app/models/fedora_rpm.rb
  19. +1 −1 app/models/ruby_gem.rb
  20. +0 −11 app/views/fedorarpms/all.html.haml
  21. +15 −0 app/views/fedorarpms/index.html.haml
  22. +5 −4 app/views/fedorarpms/show.html.haml
  23. +2 −0 app/views/gemcomments/_comments.html.haml
  24. +4 −0 app/views/gemcomments/_new_comment.html.haml
  25. +10 −0 app/views/home/show.html.haml
  26. +4 −5 app/views/layouts/application.html.haml
  27. +0 −11 app/views/rubygems/all.html.haml
  28. +15 −0 app/views/rubygems/index.html.haml
  29. +30 −4 app/views/rubygems/show.html.haml
  30. +8 −5 config/routes.rb
  31. BIN db/development.sqlite3
  32. +0 −241 public/index.html
  33. +32 −0 spec/spec_helper.rb
  34. +7 −0 test/functional/gemcomments_controller_test.rb
  35. +7 −0 test/functional/home_controller_test.rb
  36. +7 −0 test/functional/rpmcomments_controller_test.rb
  37. +4 −0 test/unit/helpers/gemcomments_helper_test.rb
  38. +4 −0 test/unit/helpers/home_helper_test.rb
  39. +4 −0 test/unit/helpers/rpmcomments_helper_test.rb
View
1 .rspec
@@ -0,0 +1 @@
+--colour
View
10 Gemfile
@@ -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
View
@@ -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)
@@ -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)
@@ -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)
@@ -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
@@ -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/
@@ -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/
@@ -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/
@@ -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/
@@ -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/
@@ -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/
@@ -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
@@ -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
@@ -0,0 +1,5 @@
+class HomeController < ApplicationController
+ def show
+ @page_title = 'Welcome'
+ end
+end
@@ -0,0 +1,2 @@
+class RpmcommentsController < ApplicationController
+end
@@ -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
@@ -0,0 +1,2 @@
+module GemcommentsHelper
+end
@@ -0,0 +1,2 @@
+module HomeHelper
+end
@@ -0,0 +1,2 @@
+module RpmcommentsHelper
+end
View
@@ -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'
View
@@ -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)
@@ -1,11 +0,0 @@
-%table
- %tr
- %th Name
- %th Version
- %th Gem
-
- - @rpms.each do |rpm|
- %tr
- %td= link_to rpm.name, fedorarpm_path(rpm.id)
- %td= rpm.version
- %td= if (rpm.ruby_gem != nil) then link_to 'View', rubygem_path(rpm.ruby_gem.id) end
@@ -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
@@ -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
@@ -0,0 +1,2 @@
+%div
+ %p= gemcomment.name
@@ -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
@@ -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
@@ -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
@@ -1,11 +0,0 @@
-%table
- %tr
- %th Name
- %th Version
- %th Rpm
-
- - @gems.each do |gem|
- %tr
- %td= link_to gem.name, rubygem_path(gem.id)
- %td= gem.version
- %td= if gem.fedora_rpm != nil then link_to 'View', fedorarpm_path(gem.fedora_rpm.id) end
@@ -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
@@ -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}
View
@@ -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'
View
Binary file not shown.
Oops, something went wrong.

0 comments on commit 911ca1b

Please sign in to comment.