Permalink
Browse files

stop using focused_controller and use classique controller

  • Loading branch information...
1 parent 241fc94 commit 9aa7ed4572e749c5547a36b62f0b658b564a5f5c @shingara committed Jun 1, 2012
View
9 Gemfile
@@ -9,12 +9,11 @@ gem 'railties', :require => 'rails'
gem 'mongoid', :git => 'git://github.com/mongoid/mongoid.git'
-gem 'focused_controller', :git => 'git://github.com/jonleighton/focused_controller.git'
-
gem 'sidekiq'
gem 'sinatra'
gem 'faraday'
gem 'draper'
+gem 'kaminari', :git => 'git://github.com/amatsuda/kaminari.git'
# Gems used only for assets and not required
# in production environments by default.
@@ -35,15 +34,17 @@ gem 'slim-rails'
gem 'simple_form'
group :development, :test do
- gem 'quiet_assets', :git => 'git://github.com/evrone/quiet_assets.git'
+ gem 'quiet_assets'
gem 'rspec-rails'
gem 'guard'
gem 'guard-rspec'
+ gem 'vagrant'
end
group :test do
- gem 'mongoid-rspec', :git => 'git://github.com/kfaustino/mongoid-rspec.git', :branch => 'mongoid-3.0'
+ gem 'mongoid-rspec', :git => 'git://github.com/evansagge/mongoid-rspec.git'
gem 'capybara'
+ gem 'fabrication'
end
## Deployment
View
159 Gemfile.lock
@@ -1,60 +1,54 @@
GIT
- remote: git://github.com/evrone/quiet_assets.git
- revision: c57d7eb06a07f064923c4c8659b29cbbaa1f8377
+ remote: git://github.com/amatsuda/kaminari.git
+ revision: 97d5f926f3b1cd1114254eff2a200c902b744683
specs:
- quiet_assets (1.0.1)
- railties (~> 3.1)
+ kaminari (0.13.0)
+ actionpack (>= 3.0.0)
+ activesupport (>= 3.0.0)
GIT
- remote: git://github.com/jonleighton/focused_controller.git
- revision: 7793d4cac83d3e4f99abd1967236fb9fccc6cbd8
+ remote: git://github.com/evansagge/mongoid-rspec.git
+ revision: cc184b8b41f3e5bac4e769444f633e9d7cf2b294
specs:
- focused_controller (0.1.0)
- actionpack (~> 3.0)
-
-GIT
- remote: git://github.com/kfaustino/mongoid-rspec.git
- revision: 7c8c3a774cd4111395995b1ccb1a31872ce30520
- branch: mongoid-3.0
- specs:
- mongoid-rspec (1.4.4)
- mongoid (~> 3.0.0)
+ mongoid-rspec (1.4.5)
+ mongoid (>= 2.4.6)
rake
- rspec (~> 2.9)
+ rspec (>= 2.9)
GIT
remote: git://github.com/mongoid/mongoid.git
- revision: 12998f280e2878320ffb6a917457c3f47aa441b5
+ revision: b49219f27270d008ba0f2058fff00ef945f28992
specs:
- mongoid (3.0.0)
+ mongoid (3.0.0.rc)
activemodel (~> 3.1)
- moped (~> 1.0.0.beta)
- origin (~> 1.0.0.beta)
+ moped (~> 1.0.0.rc)
+ origin (~> 1.0.0.rc)
tzinfo (~> 0.3.22)
GEM
remote: https://rubygems.org/
specs:
- actionmailer (3.2.3)
- actionpack (= 3.2.3)
+ actionmailer (3.2.5)
+ actionpack (= 3.2.5)
mail (~> 2.4.4)
- actionpack (3.2.3)
- activemodel (= 3.2.3)
- activesupport (= 3.2.3)
+ actionpack (3.2.5)
+ activemodel (= 3.2.5)
+ activesupport (= 3.2.5)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
- sprockets (~> 2.1.2)
- activemodel (3.2.3)
- activesupport (= 3.2.3)
+ sprockets (~> 2.1.3)
+ activemodel (3.2.5)
+ activesupport (= 3.2.5)
builder (~> 3.0.0)
- activesupport (3.2.3)
+ activesupport (3.2.5)
i18n (~> 0.6)
multi_json (~> 1.0)
- addressable (2.2.7)
+ addressable (2.2.8)
+ archive-tar-minitar (0.5.2)
builder (3.0.0)
capybara (1.1.2)
mime-types (>= 1.16)
@@ -72,35 +66,37 @@ GEM
coffee-script (2.2.0)
coffee-script-source
execjs
- coffee-script-source (1.3.1)
+ coffee-script-source (1.3.3)
commonjs (0.2.6)
connection_pool (0.9.1)
dante (0.1.3)
diff-lcs (1.1.3)
- draper (0.11.1)
- activesupport (>= 2.3.10)
+ draper (0.14.0)
+ actionpack (~> 3.2)
+ activesupport (~> 3.2)
erubis (2.7.0)
- execjs (1.3.1)
+ execjs (1.4.0)
multi_json (~> 1.0)
- faraday (0.8.0)
+ fabrication (1.4.0)
+ faraday (0.8.1)
multipart-post (~> 1.1)
ffi (1.0.11)
- guard (1.0.1)
+ guard (1.0.3)
ffi (>= 0.5.0)
- thor (~> 0.14.6)
- guard-rspec (0.7.0)
+ thor (>= 0.14.6)
+ guard-rspec (0.7.3)
guard (>= 0.10.0)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
- json (1.7.0)
+ json (1.7.3)
kgio (2.7.4)
less (2.2.1)
commonjs (~> 0.2.6)
- less-rails (2.2.2)
+ less-rails (2.2.3)
actionpack (>= 3.1)
less (~> 2.2.0)
libv8 (3.3.10.4)
@@ -110,13 +106,19 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
+ mario (0.0.6)
mime-types (1.18)
- moped (1.0.0.beta)
- multi_json (1.3.4)
+ moped (1.0.0.rc)
+ multi_json (1.3.6)
multipart-post (1.1.5)
+ net-scp (1.0.4)
+ net-ssh (>= 1.99.1)
+ net-ssh (2.5.2)
nokogiri (1.5.2)
- origin (1.0.0.beta)
+ origin (1.0.0.rc)
polyglot (0.3.3)
+ quiet_assets (1.0.1)
+ railties (~> 3.1)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
@@ -126,61 +128,61 @@ GEM
rack
rack-test (0.6.1)
rack (>= 1.0)
- railties (3.2.3)
- actionpack (= 3.2.3)
- activesupport (= 3.2.3)
+ railties (3.2.5)
+ actionpack (= 3.2.5)
+ activesupport (= 3.2.5)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
- thor (~> 0.14.6)
- raindrops (0.8.0)
+ thor (>= 0.14.6, < 2.0)
+ raindrops (0.9.0)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
- redis (2.2.2)
- redis-namespace (1.1.0)
- redis (< 3.0.0)
- rspec (2.9.0)
- rspec-core (~> 2.9.0)
- rspec-expectations (~> 2.9.0)
- rspec-mocks (~> 2.9.0)
- rspec-core (2.9.0)
- rspec-expectations (2.9.1)
+ redis (3.0.0)
+ redis-namespace (1.2.0)
+ redis (~> 3.0.0)
+ 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.9.0)
- rspec-rails (2.9.0)
+ rspec-mocks (2.10.1)
+ rspec-rails (2.10.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
- rspec (~> 2.9.0)
+ rspec (~> 2.10.0)
rubyzip (0.9.8)
rufus-scheduler (2.0.16)
tzinfo (>= 0.3.23)
- sass (3.1.16)
+ sass (3.1.19)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
- selenium-webdriver (2.21.2)
+ selenium-webdriver (2.22.1)
childprocess (>= 0.2.5)
ffi (~> 1.0)
libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
- sidekiq (1.1.4)
+ sidekiq (1.2.1)
celluloid (~> 0.10.0)
connection_pool (~> 0.9.0)
- multi_json (~> 1.0)
+ multi_json (~> 1)
redis
redis-namespace
- simple_form (2.0.1)
+ simple_form (2.0.2)
actionpack (~> 3.0)
activemodel (~> 3.0)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
- slim (1.2.0)
+ slim (1.2.1)
temple (~> 0.4.0)
tilt (~> 1.3.3)
slim-rails (1.0.3)
@@ -195,15 +197,16 @@ GEM
temple (0.4.0)
therubyracer (0.10.1)
libv8 (~> 3.3.10)
- thor (0.14.6)
+ thor (0.15.2)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
- twitter-bootstrap-rails (2.0.6)
+ twitter-bootstrap-rails (2.0.8)
actionpack (>= 3.1)
- less-rails (~> 2.2.0)
+ less-rails (~> 2.2.2)
railties (>= 3.1)
+ therubyracer (~> 0.10.1)
tzinfo (0.3.33)
uglifier (1.2.4)
execjs (>= 0.3.0)
@@ -212,6 +215,16 @@ GEM
kgio (~> 2.6)
rack
raindrops (~> 0.7)
+ vagrant (0.5.4)
+ archive-tar-minitar (= 0.5.2)
+ erubis (>= 2.6.6)
+ json (>= 1.4.3)
+ mario (~> 0.0.6)
+ net-scp (>= 1.0.2)
+ net-ssh (>= 2.0.19)
+ virtualbox (~> 0.7.3)
+ virtualbox (0.7.5)
+ ffi (>= 0.6.3)
xpath (0.1.4)
nokogiri (~> 1.3)
@@ -226,14 +239,15 @@ DEPENDENCIES
coffee-rails
dante
draper
+ fabrication
faraday
- focused_controller!
guard
guard-rspec
jquery-rails
+ kaminari!
mongoid!
mongoid-rspec!
- quiet_assets!
+ quiet_assets
railties
rspec-rails
rufus-scheduler
@@ -247,3 +261,4 @@ DEPENDENCIES
twitter-bootstrap-rails
uglifier (>= 1.0.3)
unicorn
+ vagrant
View
4 Vagrantfile
@@ -58,11 +58,11 @@ Vagrant::Config.run do |config|
chef.json = {
:host => 'pingit.dev',
:nginx => {
- :version => '1.2.0'
+ :version => '1.3.0'
},
:redis => {
:source => {
- :version => '2.4.12'
+ :version => '2.4.14'
}
}
}
View
1 app/controllers/application_controller.rb
@@ -1,4 +1,3 @@
class ApplicationController < ActionController::Base
- include FocusedController::Mixin
protect_from_forgery
end
View
58 app/controllers/urls_controller.rb
@@ -1,47 +1,37 @@
-require 'focused_controller'
-module UrlsController
+class UrlsController < ApplicationController
- class Index < ApplicationController
- def urls
- UrlDecorator.decorate(Url.all)
- end
- helper_method :urls
+ def urls
+ UrlDecorator.decorate(Url.all)
end
+ helper_method :urls
- class New < ApplicationController
- def url
- Url.new
- end
- helper_method :url
- end
+ def url; @url; end
+ helper_method :url
- class Create < ApplicationController
- def url
- @url ||= Url.create(params['url'])
- end
- helper_method :url
+ def new
+ @url = Url.new(params['url'])
+ end
- def run
- if url.persisted?
- redirect_to urls_url, :flash => { :success => t('urls.flash.create.success', :link => url.link) }
- else
- render :new
- end
- end
+ def show
+ @url = UrlDecorator.decorate(Url.find(params[:id]))
end
- class Show < ApplicationController
- def url
- UrlDecorator.decorate(Url.find(params[:id]))
+ def create
+ @url = Url.create(params['url'])
+ if url.persisted?
+ redirect_to url_url(url), {
+ :flash => {
+ :success => t('urls.flash.create.success', :link => url.link)
+ }
+ }
+ else
+ render :new
end
- helper_method :url
end
- class Destroy < ApplicationController
- def run
- if Url.find(params[:id]).destroy
- redirect_to urls_url, :flash => { :success => I18n.t('urls.flash.destroy.success') }
- end
+ def destroy
+ if Url.find(params[:id]).destroy
+ redirect_to urls_url, :flash => { :success => I18n.t('urls.flash.destroy.success') }
end
end
end
View
4 app/decorators/url_decorator.rb
@@ -16,7 +16,9 @@ def link
end
def ping_statuses
- PingStatusDecorator.decorate url.ping_statuses.desc(:updated_at)
+ PingStatusDecorator.decorate(
+ url.ping_statuses.desc(:updated_at).page(h.params[:page])
+ )
end
def to_param
View
13 app/views/kaminari/_first_page.html.erb
@@ -0,0 +1,13 @@
+<%# Link to the "First" page
+ - available local variables
+ url: url to the first page
+ current_page: a page object for the currently displayed page
+ num_pages: total number of pages
+ per_page: number of items to fetch per page
+ remote: data-remote
+-%>
+<% unless current_page.first? %>
+<li class="first">
+ <%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, :remote => remote %>
+</li>
+<% end %>
View
8 app/views/kaminari/_gap.html.erb
@@ -0,0 +1,8 @@
+<%# Non-link tag that stands for skipped pages...
+ - available local variables
+ current_page: a page object for the currently displayed page
+ num_pages: total number of pages
+ per_page: number of items to fetch per page
+ remote: data-remote
+-%>
+<li class="page gap disabled"><a href="#" onclick="return false;"><%= raw(t 'views.pagination.truncate') %></a></li>
View
13 app/views/kaminari/_last_page.html.erb
@@ -0,0 +1,13 @@
+<%# Link to the "Last" page
+ - available local variables
+ url: url to the last page
+ current_page: a page object for the currently displayed page
+ num_pages: total number of pages
+ per_page: number of items to fetch per page
+ remote: data-remote
+-%>
+<% unless current_page.last? %>
+<li class="last next"><%# "next" class present for border styling in twitter bootstrap %>
+ <%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote} %>
+</li>
+<% end %>
View
13 app/views/kaminari/_next_page.html.erb
@@ -0,0 +1,13 @@
+<%# Link to the "Next" page
+ - available local variables
+ url: url to the next page
+ current_page: a page object for the currently displayed page
+ num_pages: total number of pages
+ per_page: number of items to fetch per page
+ remote: data-remote
+-%>
+<% unless current_page.last? %>
+<li class="next_page">
+ <%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, :rel => 'next', :remote => remote %>
+</li>
+<% end %>
View
12 app/views/kaminari/_page.html.erb
@@ -0,0 +1,12 @@
+<%# Link showing page number
+ - available local variables
+ page: a page object for "this" page
+ url: url to this page
+ current_page: a page object for the currently displayed page
+ num_pages: total number of pages
+ per_page: number of items to fetch per page
+ remote: data-remote
+-%>
+<li class="page<%= ' active' if page.current? %>">
+ <%= link_to page, url, opts = {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
+</li>
View
25 app/views/kaminari/_paginator.html.erb
@@ -0,0 +1,25 @@
+<%# The container tag
+ - available local variables
+ current_page: a page object for the currently displayed page
+ num_pages: total number of pages
+ per_page: number of items to fetch per page
+ remote: data-remote
+ paginator: the paginator that renders the pagination tags inside
+-%>
+<%= paginator.render do -%>
+ <div class="pagination">
+ <ul>
+ <%= first_page_tag unless current_page.first? %>
+ <%= prev_page_tag unless current_page.first? %>
+ <% each_page do |page| -%>
+ <% if page.left_outer? || page.right_outer? || page.inside_window? -%>
+ <%= page_tag page %>
+ <% elsif !page.was_truncated? -%>
+ <%= gap_tag %>
+ <% end -%>
+ <% end -%>
+ <%= next_page_tag unless current_page.last? %>
+ <%= last_page_tag unless current_page.last? %>
+ </ul>
+ </div>
+<% end -%>
View
13 app/views/kaminari/_prev_page.html.erb
@@ -0,0 +1,13 @@
+<%# Link to the "Previous" page
+ - available local variables
+ url: url to the previous page
+ current_page: a page object for the currently displayed page
+ num_pages: total number of pages
+ per_page: number of items to fetch per page
+ remote: data-remote
+-%>
+<% unless current_page.first? %>
+<li class="prev">
+ <%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote %>
+</li>
+<% end %>
View
2 app/views/urls/show.html.slim
@@ -31,3 +31,5 @@ h2= t('.overview')
td= ping_status.date
td= ping_status.status
td= ping_status.response_time
+
+ = paginate url.ping_statuses
View
9 config/initializers/kaminari_config.rb
@@ -0,0 +1,9 @@
+Kaminari.configure do |config|
+ # config.default_per_page = 25
+ # config.window = 4
+ # config.outer_window = 0
+ # config.left = 0
+ # config.right = 0
+ # config.page_method_name = :page
+ # config.param_name = :page
+end
View
7 config/routes.rb
@@ -1,10 +1,9 @@
Pingit::Application.routes.draw do
- focused_controller_routes do
- resources :urls
- end
+
+ resources :urls
require 'sidekiq/web'
mount Sidekiq::Web => '/sidekiq'
- root :to => proc { |env| UrlsController::Index.call(env) }
+ root :to => "urls#index"
end
View
92 spec/controllers/urls_controller_spec.rb
@@ -1,83 +1,31 @@
require 'spec_helper'
describe UrlsController do
- describe UrlsController::Index do
-
- let(:controller) { UrlsController::Index.new }
-
- describe "#urls" do
-
- context "without params" do
- it 'should return all urls' do
- controller.urls.should == Url.all
- end
- end
- end
+ describe "get /urls" do
+ before { get :index }
+ it { response.should be_success }
+ it { response.should render_template('urls/index') }
end
- describe UrlsController::New do
-
- let(:controller) { UrlsController::New.new }
-
- describe "#urls" do
- it 'should return an url' do
- controller.url.should be_a(Url)
- end
- end
+ describe "get /urls/new" do
+ before { get :new }
+ it { response.should be_success }
+ it { response.should render_template("urls/new") }
+ it { assigns(:url).should_not be_persisted }
end
- describe UrlsController::Create do
- let(:controller) { UrlsController::Create.new }
- context "with params" do
- let(:link) { 'http://hello.com' }
- before do
- controller.params = {'url' => {'link' => link} }
- end
-
- describe '#url' do
- it 'create an Url model' do
- lambda do
- controller.url
- end.should change(Url, :count)
- end
-
- it 'return an Url model' do
- controller.url.should be_a(Url)
- end
-
- it 'return an url persisted' do
- controller.url.should be_persisted
- end
-
- it 'create an url with link' do
- controller.url.link.should == link
- end
-
- it 'should not create several url model if call several times' do
- lambda do
- 2.times { controller.url }
- end.should change(Url, :count).by(1)
- end
- end
- end
-
+ describe "post /urls" do
+ before { post :create, :url => {:link => 'http://google.com'} }
+ it { response.should redirect_to(url_url(assigns(:url))) }
+ it { flash[:success].should eq I18n.t('urls.flash.create.success', :link => assigns(:url).link) }
+ it { assigns(:url).should be_persisted }
end
- describe UrlsController::Show do
- let(:url) { Url.new }
- let(:controller) { UrlsController::Show.new }
- describe '#url' do
- before do
- Url.should_receive(:find).with(url.id.to_s).and_return { url }
- controller.params = { id: url.id.to_s }
- end
- it 'return an Url model' do
- controller.url.should be_a(UrlDecorator)
- end
- it 'return url with id pass in args' do
- controller.url.should eq(url)
- end
- end
-
+ describe "get /urls/:id" do
+ let(:url) { Fabricate(:url) }
+ before { get :show, :id => url.to_param }
+ it { response.should be_success }
+ it { assigns(:url).should eq UrlDecorator.decorate(url) }
end
+
end
View
2 spec/decorators/url_decorator_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe UrlDecorator do
- let(:url) { Url.new }
+ let(:url) { Fabricate(:url) }
let(:decorator) { UrlDecorator.decorate(url) }
describe 'uptime' do
View
4 spec/fabricators/ping_status_fabricator.rb
@@ -0,0 +1,4 @@
+Fabricator(:ping_status) do
+ status 200
+ response_time { rand(100) / 100 }
+end
View
4 spec/fabricators/url_fabricator.rb
@@ -0,0 +1,4 @@
+Fabricator(:url) do
+ link 'http://google.com'
+ ping_statuses(:count => 1) { |parent| Fabricate(:ping_status, :url => parent) }
+end
View
1 spec/models/ping_status_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe PingStatus do
+ it { Fabricate(:ping_status).should be_valid }
describe "Attributes" do
it { should have_field(:status).of_type(Integer) }
it { should have_field(:response_time).of_type(Float) }
View
3 spec/models/url_spec.rb
@@ -1,6 +1,9 @@
require 'spec_helper'
describe Url do
+
+ it { Fabricate(:url).should be_valid }
+
describe "Attributes" do
it { should have_field(:link).of_type(String) }
end
View
10 spec/routing_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe "url resource" do
+ it 'should see /urls' do
+ get('/urls').should route_to(
+ :controller => 'urls',
+ :action => 'index'
+ )
+ end
+end
View
6 spec/views/urls/show.html.slim_spec.rb
@@ -3,9 +3,13 @@
describe 'show.html.slim' do
include DecoratorHelper
+ let(:url_decorate) {
+ UrlDecorator.decorate(Fabricate.build(:url))
+ }
+
before do
setup_decorator
- view.stub(:url) { UrlDecorator.decorate(Url.new) }
+ view.stub(:url) { url_decorate }
render :template => 'urls/show'
end
it 'should have title' do

0 comments on commit 9aa7ed4

Please sign in to comment.