Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated project, now we use padrino-contrib e latest MongoMapper vers…

…ion.
  • Loading branch information...
commit 1d351a645159566aeeb4c7f48a63c69695af2a9c 1 parent ba7e570
@DAddYE DAddYE authored
View
13 Gemfile
@@ -1,4 +1,4 @@
-source :gemcutter
+source :rubygems
# Project requirements
gem 'rack-flash'
@@ -8,8 +8,8 @@ gem 'popen4'
# Component requirements
gem 'haml'
-gem 'bson_ext', '1.0.1', :require => nil
-gem 'mongo_mapper', '0.8.0'
+gem 'bson_ext', '>=1.0.4', :require => nil
+gem 'mongo_mapper', '0.8.2'
gem 'diff-lcs', :require => 'diff/lcs'
gem 'disqus'
@@ -17,9 +17,12 @@ gem 'disqus'
gem 'rspec', :require => "spec", :group => "test"
gem 'rack-test', :require => "rack/test", :group => "test"
-# Padrino
+# Padrino EDGE
# %w(core gen helpers mailer admin).each do |gem|
# gem 'padrino-' + gem, :path => '/src/padrino-framework/padrino-' + gem
# end
+#
+# gem 'padrino-contrib', :path => '/src/padrino-contrib'
-gem 'padrino', '0.9.14'
+gem 'padrino', '0.9.14'
+gem 'padrino-contrib', '0.0.2'
View
2  admin/mailers/guide.rb
@@ -1,5 +1,5 @@
Admin.mailer :guide do
- defaults :form => Admin.email_from
+ defaults :from => Admin.email_from
email :added do |guide|
to Account.all.collect(&:email)
View
2  admin/mailers/notifier.rb
@@ -1,5 +1,5 @@
Admin.mailer :notifier do
- defaults :form => Admin.email_from
+ defaults :from => Admin.email_from
email :registration do |account|
to account.email
View
2  admin/mailers/page.rb
@@ -1,5 +1,5 @@
Admin.mailer :page do
- defaults :form => Admin.email_from
+ defaults :from => Admin.email_from
email :added do |page|
to Account.all.collect(&:email)
View
2  admin/mailers/post.rb
@@ -1,5 +1,5 @@
Admin.mailer :post do
- defaults :form => Admin.email_from
+ defaults :from => Admin.email_from
email :added do |post|
to Account.all.collect(&:email)
View
7 app/app.rb
@@ -1,8 +1,13 @@
class PadrinoWeb < Padrino::Application
register Padrino::Helpers
- register ExceptionNotifier
+ register Padrino::Mailer
+ register Padrino::Contrib::ExceptionNotifier
+
set :exceptions_subject, "PadrinoWeb"
set :exceptions_from, "Padrino WebSite <exceptions@padrinorb.com>"
set :exceptions_to, Account.all.map(&:email)
set :exceptions_page, "base/errors"
+ # # Uncomment this for test in development
+ # disable :raise_errors
+ # disable :show_exceptions
end # PadrinoWeb
View
16 app/models/post.rb
@@ -1,12 +1,12 @@
class Post
include MongoMapper::Document
- key :title, String, :required => true
- key :summary, String, :required => true
+ key :title, String, :required => true
+ key :summary, String, :required => true
key :body, String
key :tags, String
- key :draft, Boolean, :default => true
- key :category_ids, Array
+ key :draft, Boolean, :default => true
+ key :category_ids, Array, :typecast => 'ObjectId'
key :author_id, ObjectId, :required => true
belongs_to :author, :class_name => "Account", :foreign_key => "author_id"
@@ -24,14 +24,6 @@ class Post
def self.per_page; 10; end
- ##
- # For unknow reasons "key :category_ids, Array, :typecast => 'ObjectId'" didn't work
- #
- def category_ids=(ids)
- categories = ids.map { |id| Category.find(id) rescue nil }.compact
- super(categories.map(&:id))
- end
-
private
def send_notification
Admin.deliver(:post, :added, self)
View
9 config/boot.rb
@@ -18,9 +18,16 @@
##
# REE
# http://www.rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
-#
+#
if GC.respond_to?(:copy_on_write_friendly=)
GC.copy_on_write_friendly = true
end
+##
+# Padrino contrib stuff
+#
+require 'padrino-contrib/exception_notifier'
+require 'padrino-contrib/orm/mm/permalink'
+require 'padrino-contrib/orm/mm/search'
+
Padrino.load!
View
2  lib/disqus.rb
@@ -38,4 +38,4 @@
:num_items => 15, # number of comments to display
:show_powered_by => true, # show or hide powered by line
:orientation => "horizontal" # comment orientation
-})
+}) unless PADRINO_ENV == "test" # don't tell me why bundler 1.0 didn't load it on test
View
50 lib/exception_notifier.rb
@@ -1,50 +0,0 @@
-##
-# This is an exception notifier for Padrino::Application with
-# redmine bonus feature.
-#
-# ==== Usage
-#
-# class MyApp < Padrino::Application
-# register ExceptionNotifier
-# set :exceptions_from, "errors@localhost.local"
-# set :exceptions_to, "foo@bar.local"
-# set :exceptions_page, :errors # => views/errors.haml/erb
-# set :redmine, :project => "My Bugs", :tracker => "Bugs", :priority => "High"
-# # Uncomment this for test in development
-# # disable :raise_errors
-# # disable :show_exceptions
-# end
-#
-module ExceptionNotifier
-
- def self.registered(app)
- app.set :exceptions_subject, "Exception"
- app.set :exceptions_to, "errors@localhost.local"
- app.set :exceptions_from, "foo@bar.local"
- app.set :redmine, {}
- app.error 500 do
- boom = env['sinatra.error']
- body = ["#{boom.class} - #{boom.message}:", *boom.backtrace].join("\n ")
- body += "\n\n---Env:\n"
- env.each { |k,v| body += "\n#{k}: #{v}" }
- body += "\n\n---Params:\n"
- params.each { |k,v| body += "\n#{k.inspect} => #{v.inspect}" }
- logger.error body
- options.redmine.each { |k,v| body += "\n#{k.to_s.capitalize}: #{v}" }
- Padrino::Mailer::MailObject.new(
- :subject => "[#{options.exceptions_subject}] #{boom.class} - #{boom.message}",
- :to => options.exceptions_to,
- :from => options.exceptions_from,
- :body => body
- ).deliver
- response.status = 500
- content_type 'text/html', :charset => "utf-8"
- render options.exceptions_page
- end
- app.error 404 do
- response.status = 404
- content_type 'text/html', :charset => "utf-8"
- render options.exceptions_page
- end
- end
-end
View
42 lib/permalink.rb
@@ -1,42 +0,0 @@
-##
-# This module extend ActiveRecord.
-#
-# You need to to your model a column called +:permalink+
-#
-# then use +has_permalink :title like:
-#
-# class Page < ActiveRecord::Base
-# has_permalink :page
-# end
-#
-module Permalink
- module ClassMethods
- def has_permalink(field)
- include InstanceMethods
- class_inheritable_accessor :permalink_field
- write_inheritable_attribute :permalink_field, field
- before_save :generate_permalink
- validates_uniqueness_of field
- key :permalink, String
- end
-
- def permalink_for(name)
- name.downcase.gsub(/\W/, '-').
- gsub(/-+/, '-').
- gsub(/-$/, '').
- gsub(/^-/, '')
- end
- end
-
- module InstanceMethods
- def to_param
- permalink
- end
-
- protected
- def generate_permalink
- self.permalink = self.class.permalink_for(self[permalink_field])
- end
- end # InstanceMethods
-end # Permalink
-MongoMapper::Document.append_extensions(Permalink::ClassMethods)
View
18 lib/search.rb
@@ -1,18 +0,0 @@
-module Search
- module ClassMethods
- def has_search(*fields)
- class_inheritable_accessor :search_fields
- write_inheritable_attribute :search_fields, fields
- end
-
- def search(text, options={})
- if text
- re = Regexp.new(Regexp.escape(text), 'i').to_json
- where = search_fields.map { |field| "this.#{field}.match(#{re})" }.join(" || ")
- options.merge!("$where" => where)
- end
- options.delete(:paginate) ? paginate(options) : all(options)
- end
- end
-end # Permalink
-MongoMapper::Document.append_extensions(Search::ClassMethods)
View
12 spec/models/account_spec.rb
@@ -25,23 +25,23 @@
it 'cannot be destroyed if has posts' do
post = @account.posts.create(:title => 'Foo', :summary => 'Bar')
- @account.posts.should_not be_empty
+ @account.posts.all.should_not be_empty
@account.destroy.should be_false
- @account.posts.should_not be_empty
+ @account.posts.all.should_not be_empty
end
it 'cannot be destroyed if has guides' do
guide = @account.guides.create(:title => 'Foo', :body => 'Bar')
- @account.guides.should_not be_empty
+ @account.guides.all.should_not be_empty
@account.destroy.should be_false
- @account.guides.should_not be_empty
+ @account.guides.all.should_not be_empty
end
it 'cannot be destroyed if has pages' do
page = @account.pages.create(:title => 'Foo', :body => 'Bar', :label_name => 'Foo')
- @account.pages.should_not be_empty
+ @account.pages.all.should_not be_empty
@account.destroy.should be_false
- @account.pages.should_not be_empty
+ @account.pages.all.should_not be_empty
end
it 'create correctly the textile formatted for description' do
View
10 spec/models/post_spec.rb
@@ -86,14 +86,22 @@
end
context 'categories' do
+ before do
+ Category.delete_all
+ end
+
it 'associate correctly categories' do
categories = %w(press news ruby).map { |name| Category.create(:name => name) }
post = @account.posts.create(:title => 'Last News', :summary => "Last news")
post.should_not be_nil
+ post.categories.should be_empty
post.categories = categories
post.save
post.categories.should == categories
- post = @account.posts.create(:title => 'Last Blog News', :summary => "Last blog news", :category_ids => categories.map(&:id).flatten)
+ # Simulation of an html form
+ post.should respond_to(:category_ids=)
+ category_ids = categories.map { |c| c.id.to_s }.flatten
+ post = @account.posts.create(:title => 'Last Blog News', :summary => "Last blog news", :category_ids => category_ids)
post.should_not be_nil
post.categories.should == categories
end
View
4 spec/spec_helper.rb
@@ -11,7 +11,3 @@
Admin.setup_application!
PadrinoWeb.setup_application!
-
-def app
- PadrinoWeb.tap { |app| }
-end

0 comments on commit 1d351a6

Please sign in to comment.
Something went wrong with that request. Please try again.