Permalink
Browse files

commit inicial

  • Loading branch information...
0 parents commit 8f66de1159bc41707d576e576204e69910e9dd34 @Draiken committed Apr 1, 2011
Showing with 11,133 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +1 −0 .rvmrc
  3. +17 −0 Gemfile
  4. +135 −0 Gemfile.lock
  5. +20 −0 MIT-LICENSE
  6. +3 −0 README.rdoc
  7. +28 −0 Rakefile
  8. +11 −0 features/add_comment.feature
  9. +15 −0 features/step_definitions/common_steps.rb
  10. +60 −0 features/support/env.rb
  11. +7 −0 lib/opinio.rb
  12. BIN lib/opinio/.opinio.rb.swp
  13. BIN lib/opinio/.railtie.rb.swp
  14. +79 −0 lib/opinio/opinio_model.rb
  15. +19 −0 lib/opinio/orm/active_record.rb
  16. +16 −0 lib/opinio/railtie.rb
  17. +19 −0 lib/opinio/schema.rb
  18. +9 −0 opinio.gemspec
  19. +7 −0 spec/dummy/Rakefile
  20. +3 −0 spec/dummy/app/controllers/application_controller.rb
  21. +83 −0 spec/dummy/app/controllers/comments_controller.rb
  22. +83 −0 spec/dummy/app/controllers/posts_controller.rb
  23. +83 −0 spec/dummy/app/controllers/users_controller.rb
  24. +2 −0 spec/dummy/app/helpers/application_helper.rb
  25. +2 −0 spec/dummy/app/helpers/comments_helper.rb
  26. +2 −0 spec/dummy/app/helpers/posts_helper.rb
  27. +2 −0 spec/dummy/app/helpers/users_helper.rb
  28. +3 −0 spec/dummy/app/models/comment.rb
  29. +2 −0 spec/dummy/app/models/post.rb
  30. +2 −0 spec/dummy/app/models/user.rb
  31. +17 −0 spec/dummy/app/views/comments/_form.html.erb
  32. +6 −0 spec/dummy/app/views/comments/edit.html.erb
  33. +21 −0 spec/dummy/app/views/comments/index.html.erb
  34. +5 −0 spec/dummy/app/views/comments/new.html.erb
  35. +5 −0 spec/dummy/app/views/comments/show.html.erb
  36. +14 −0 spec/dummy/app/views/layouts/application.html.erb
  37. +25 −0 spec/dummy/app/views/posts/_form.html.erb
  38. +6 −0 spec/dummy/app/views/posts/edit.html.erb
  39. +25 −0 spec/dummy/app/views/posts/index.html.erb
  40. +5 −0 spec/dummy/app/views/posts/new.html.erb
  41. +15 −0 spec/dummy/app/views/posts/show.html.erb
  42. +21 −0 spec/dummy/app/views/users/_form.html.erb
  43. +6 −0 spec/dummy/app/views/users/edit.html.erb
  44. +23 −0 spec/dummy/app/views/users/index.html.erb
  45. +5 −0 spec/dummy/app/views/users/new.html.erb
  46. +10 −0 spec/dummy/app/views/users/show.html.erb
  47. +4 −0 spec/dummy/config.ru
  48. +45 −0 spec/dummy/config/application.rb
  49. +10 −0 spec/dummy/config/boot.rb
  50. +8 −0 spec/dummy/config/cucumber.yml
  51. +25 −0 spec/dummy/config/database.yml
  52. +5 −0 spec/dummy/config/environment.rb
  53. +26 −0 spec/dummy/config/environments/development.rb
  54. +49 −0 spec/dummy/config/environments/production.rb
  55. +35 −0 spec/dummy/config/environments/test.rb
  56. +7 −0 spec/dummy/config/initializers/backtrace_silencers.rb
  57. +10 −0 spec/dummy/config/initializers/inflections.rb
  58. +5 −0 spec/dummy/config/initializers/mime_types.rb
  59. +7 −0 spec/dummy/config/initializers/secret_token.rb
  60. +8 −0 spec/dummy/config/initializers/session_store.rb
  61. +5 −0 spec/dummy/config/locales/en.yml
  62. +64 −0 spec/dummy/config/routes.rb
  63. +14 −0 spec/dummy/db/migrate/20110401180341_create_posts.rb
  64. +13 −0 spec/dummy/db/migrate/20110401180356_create_users.rb
  65. +13 −0 spec/dummy/db/migrate/20110401185623_create_comments.rb
  66. +35 −0 spec/dummy/db/schema.rb
  67. +219 −0 spec/dummy/features/step_definitions/web_steps.rb
  68. +57 −0 spec/dummy/features/support/env.rb
  69. +33 −0 spec/dummy/features/support/paths.rb
  70. +53 −0 spec/dummy/lib/tasks/cucumber.rake
  71. +26 −0 spec/dummy/public/404.html
  72. +26 −0 spec/dummy/public/422.html
  73. +26 −0 spec/dummy/public/500.html
  74. 0 spec/dummy/public/favicon.ico
  75. +2 −0 spec/dummy/public/javascripts/application.js
  76. +965 −0 spec/dummy/public/javascripts/controls.js
  77. +974 −0 spec/dummy/public/javascripts/dragdrop.js
  78. +1,123 −0 spec/dummy/public/javascripts/effects.js
  79. +6,001 −0 spec/dummy/public/javascripts/prototype.js
  80. +191 −0 spec/dummy/public/javascripts/rails.js
  81. 0 spec/dummy/public/stylesheets/.gitkeep
  82. +56 −0 spec/dummy/public/stylesheets/scaffold.css
  83. +10 −0 spec/dummy/script/cucumber
  84. +6 −0 spec/dummy/script/rails
  85. +9 −0 spec/integration/navigation_spec.rb
  86. +7 −0 spec/opinio_spec.rb
  87. +33 −0 spec/spec_helper.rb
@@ -0,0 +1,6 @@
+.bundle/
+log/*.log
+pkg/
+spec/dummy/db/*.sqlite3
+spec/dummy/log/*.log
+spec/dummy/tmp/
@@ -0,0 +1 @@
+rvm use 1.9.2@opinio
@@ -0,0 +1,17 @@
+source "http://rubygems.org"
+
+gemspec
+
+gem "rails", "~> 3.0.4"
+gem "sqlite3"
+
+group :test do
+ gem "cucumber"
+ gem "cucumber-rails"
+ gem "capybara"
+ gem "database_cleaner"
+ gem "rspec-rails"
+end
+# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
+# gem 'ruby-debug'
+# gem 'ruby-debug19'
@@ -0,0 +1,135 @@
+PATH
+ remote: .
+ specs:
+ opinio (0.0.1)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.5)
+ actionpack (= 3.0.5)
+ mail (~> 2.2.15)
+ actionpack (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.13)
+ rack-test (~> 0.5.7)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.5)
+ activesupport (= 3.0.5)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ activesupport (3.0.5)
+ arel (2.0.9)
+ builder (2.1.2)
+ capybara (0.4.1.2)
+ celerity (>= 0.7.9)
+ culerity (>= 0.2.4)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (>= 0.0.27)
+ xpath (~> 0.1.3)
+ celerity (0.8.9)
+ childprocess (0.1.8)
+ ffi (~> 1.0.6)
+ cucumber (0.10.2)
+ builder (>= 2.1.2)
+ diff-lcs (>= 1.1.2)
+ gherkin (>= 2.3.5)
+ json (>= 1.4.6)
+ term-ansicolor (>= 1.0.5)
+ cucumber-rails (0.3.2)
+ cucumber (>= 0.8.0)
+ culerity (0.2.15)
+ database_cleaner (0.6.6)
+ diff-lcs (1.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ ffi (1.0.7)
+ rake (>= 0.8.7)
+ gherkin (2.3.5)
+ json (>= 1.4.6)
+ i18n (0.5.0)
+ json (1.5.1)
+ json_pure (1.5.1)
+ mail (2.2.15)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ nokogiri (1.4.4)
+ polyglot (0.3.1)
+ rack (1.2.2)
+ rack-mount (0.6.14)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.5)
+ actionmailer (= 3.0.5)
+ actionpack (= 3.0.5)
+ activerecord (= 3.0.5)
+ activeresource (= 3.0.5)
+ activesupport (= 3.0.5)
+ bundler (~> 1.0)
+ railties (= 3.0.5)
+ railties (3.0.5)
+ actionpack (= 3.0.5)
+ activesupport (= 3.0.5)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.8.7)
+ rspec (2.0.1)
+ rspec-core (~> 2.0.1)
+ rspec-expectations (~> 2.0.1)
+ rspec-mocks (~> 2.0.1)
+ rspec-core (2.0.1)
+ rspec-expectations (2.0.1)
+ diff-lcs (>= 1.1.2)
+ rspec-mocks (2.0.1)
+ rspec-core (~> 2.0.1)
+ rspec-expectations (~> 2.0.1)
+ rspec-rails (2.0.1)
+ rspec (~> 2.0.0)
+ rubyzip (0.9.4)
+ selenium-webdriver (0.1.4)
+ childprocess (>= 0.1.7)
+ ffi (>= 1.0.7)
+ json_pure
+ rubyzip
+ sqlite3 (1.3.3)
+ term-ansicolor (1.0.5)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.25)
+ xpath (0.1.3)
+ nokogiri (~> 1.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ capybara
+ cucumber
+ cucumber-rails
+ database_cleaner
+ opinio!
+ rails (~> 3.0.4)
+ rspec-rails
+ sqlite3
@@ -0,0 +1,20 @@
+Copyright 2011 YOURNAME
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
+= Opinio
+
+This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,28 @@
+# encoding: UTF-8
+require 'rubygems'
+begin
+ require 'bundler/setup'
+rescue LoadError
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
+end
+
+require 'rake'
+require 'rake/rdoctask'
+
+require 'cucumber'
+require 'cucumber/rake/task'
+
+require 'rspec/core'
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec)
+
+task :default => :spec
+
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Opinio'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README.rdoc')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
@@ -0,0 +1,11 @@
+Feature: Add a comment to something
+ In order to comment on something
+ As the user of the site
+ I want to leave my comments on that something
+
+ @javascript
+ Scenario: Add a comment
+ When I visit a page with comments
+ Then I fill "Comment" with "I love to comment"
+ And press "Send Comment"
+ Then I should see "Comment sent."
@@ -0,0 +1,15 @@
+When /^I visit a page with comments$/ do
+ pending # express the regexp above with the code you wish you had
+end
+
+Then /^I fill "([^"]*)" with "([^"]*)"$/ do |arg1, arg2|
+ pending # express the regexp above with the code you wish you had
+end
+
+Then /^press "([^"]*)"$/ do |arg1|
+ pending # express the regexp above with the code you wish you had
+end
+
+Then /^I should see "([^"]*)"$/ do |arg1|
+ pending # express the regexp above with the code you wish you had
+end
@@ -0,0 +1,60 @@
+# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
+# It is recommended to regenerate this file in the future when you upgrade to a
+# newer version of cucumber-rails. Consider adding your own code to a new file
+# instead of editing this one. Cucumber will automatically load all features/**/*.rb
+# files.
+
+ENV["RAILS_ENV"] ||= "test"
+require File.expand_path(File.dirname(__FILE__) + '/../../spec/dummy/config/environment')
+
+require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
+require 'cucumber/rails/world'
+require 'cucumber/rails/active_record'
+require 'cucumber/web/tableish'
+
+require 'capybara/rails'
+require 'capybara/cucumber'
+require 'capybara/session'
+
+#require 'capybara/envjs'
+
+#require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript
+# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
+# order to ease the transition to Capybara we set the default here. If you'd
+# prefer to use XPath just remove this line and adjust any selectors in your
+# steps to use the XPath syntax.
+Capybara.default_selector = :css
+
+# If you set this to false, any error raised from within your app will bubble
+# up to your step definition and out to cucumber unless you catch it somewhere
+# on the way. You can make Rails rescue errors and render error pages on a
+# per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
+#
+# If you set this to true, Rails will rescue all errors and render error
+# pages, more or less in the same way your application would behave in the
+# default production environment. It's not recommended to do this for all
+# of your scenarios, as this makes it hard to discover errors in your application.
+ActionController::Base.allow_rescue = false
+
+# If you set this to true, each scenario will run in a database transaction.
+# You can still turn off transactions on a per-scenario basis, simply tagging
+# a feature or scenario with the @no-txn tag. If you are using Capybara,
+# tagging with @culerity or @javascript will also turn transactions off.
+#
+# If you set this to false, transactions will be off for all scenarios,
+# regardless of whether you use @no-txn or not.
+#
+# Beware that turning transactions off will leave data in your database
+# after each scenario, which can lead to hard-to-debug failures in
+# subsequent scenarios. If you do this, we recommend you create a Before
+# block that will explicitly put your database in a known state.
+Cucumber::Rails::World.use_transactional_fixtures = true
+# How to clean your database when transactions are turned off. See
+# http://github.com/bmabey/database_cleaner for more info.
+if defined?(ActiveRecord::Base)
+ begin
+ require 'database_cleaner'
+ DatabaseCleaner.strategy = :truncation
+ rescue LoadError => ignore_if_database_cleaner_not_present
+ end
+end
@@ -0,0 +1,7 @@
+module Opinio
+ #autoload :Railtie, 'opinio/railtie'
+ autoload :Schema, 'opinio/schema'
+
+ require File.join(File.dirname(__FILE__), 'opinio', 'railtie')
+ require File.join(File.dirname(__FILE__), 'opinio', 'orm', 'active_record')
+end
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,79 @@
+module Opinio
+ module OpinioModel
+
+ def self.included(base)
+ base.extend ClassMethods
+ end
+
+ module ClassMethods
+
+ def opinio(*args)
+ options = args.extract_options!
+ debugger
+
+ attr_accessible :title if self.column_names.include?("title")
+ attr_accessible :body
+
+ commentable_options = { :polymorphic => true }
+ if options[:counter_cache]
+ commentable_options.merge(:counter_cache => options[:counter_cache])
+ end
+
+ belongs_to :commentable, commentable_options
+ belongs_to :owner, :class_name => options.merge(:belongs_to => :user)[:belongs_to]
+
+ #TODO: refactor this
+ if options[:time]
+ validate :last_comment_time, :if => :new_record?
+ cattr_accessor :comments_interval
+ self.comments_interval = options[:time]
+ end
+
+ if options[:size]
+ type = ( options[:size].is_a?(Range) ? :within : :minimum )
+ extra_options = { type => options[:size] }
+ end
+
+ validates :body,
+ { :presence => true }
+ .merge(extra_options)
+
+ validates_presence_of :commentable
+
+ send :include, Opinio::OpinioModel::InstanceMethods
+
+# if options[:has_replies]
+# before_destroy :check_comments_comments
+# validate :can_not_be_comment_of_a_comment_comment
+# opinio_subjectus :order => 'ASC'
+# end
+
+ end
+ end
+
+ module InstanceMethods
+
+ private
+
+ def last_comment_time
+ last_comment = self.owner.comments.last
+ if last_comment
+ if (Time.now - last_comment.created_at).round >= self.comments_interval
+ true
+ else
+ errors.add(
+ :created_at,
+ I18n.t('opinio.comment_interval',
+ :time => self.comments_interval,
+ :default => "You must wait %{time} seconds to comment again.")
+ )
+ false
+ end
+ else
+ true
+ end
+ end
+
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 8f66de1

Please sign in to comment.