polemic 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_Store
6
+ .rvmrc
7
+ log/*
@@ -0,0 +1,10 @@
1
+ before_script:
2
+ - "psql -c 'create database polemic_test;' -U postgres"
3
+ language: ruby
4
+ rvm:
5
+ - 1.8.7
6
+ - 1.9.2
7
+ - 1.9.3
8
+ notifications:
9
+ email:
10
+ - shatrov@me.com
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in inboxes.gemspec
4
+ gemspec
@@ -0,0 +1,52 @@
1
+ #Polemic
2
+
3
+ [![Build Status](https://secure.travis-ci.org/evrone/polemic.png)](http://travis-ci.org/evrone/polemic)
4
+
5
+ Polemic is comments engine for Rails app. It:
6
+
7
+ - provides has_polemic method to any model
8
+ - use User model as commentator
9
+ - provides `polemic_for @your_object` helper to display the object comments in views.
10
+
11
+ ##Requirements and recommendations
12
+
13
+ Polemic requires Rails 3.x and [Devise](https://github.com/plataformatec/devise) for user identification (surely, comments are not possible without users). This version of the gem is tested only with MRI 1.8.7, MRI 1.9.3, and REE.
14
+
15
+ Remember that unfortunately, Polemic reserves `Comment` for resource name.
16
+
17
+ ##Installation
18
+
19
+ 1. Run `rails g polemic:install` and `rake db:migrate`
20
+ 2. Add `has_polemic` to your model, for example Post
21
+ 3. Add `<%= polemic_for @your_object %>` to the `show` template, for example: `<%= polemic_for @post %>` to `app/views/posts/show.html.erb` for Post resource.
22
+ 4. ???
23
+ 5. PROFIT!
24
+
25
+ In CanCan is enabled in your project, you will have to add some abilities for creating Comments, for example:
26
+ ```ruby
27
+ can [:create, :read], Comment
28
+ ```
29
+ If you have no CanCan, Polemic will not use `authorize_resource` in CommentsController.
30
+ You can use hint from [Devise Wiki](https://github.com/plataformatec/devise/wiki/How-To:-Create-Haml-and-Slim-Views) to directly convert Polemic ERB views to HAML.
31
+
32
+ ##Themes and views
33
+
34
+ Polemic supports theming and usage of custom views. Firstly, you should copy default views with generator: `rails generate polemic:views`
35
+
36
+ Then, you will have polemic views in `app/views/polemic/default`. Rename `default` directory to according model or controller name, for example `posts`. Don't forget to replace paths in `_comments.html.erb` view: `polemic/default/` => `polemic/posts/`
37
+
38
+ Also, you should specify the theme as param for `polemic_for` helper in the commentable object views:
39
+
40
+ `polemic_for(@post, :theme => "posts")`
41
+
42
+ ##Todo
43
+
44
+ - Add RSpec tests
45
+ - Add Faye support
46
+ - Do not hardcode `User` model as a commentator
47
+
48
+ ##Authors
49
+
50
+ - [Kir Shatrov](https://github.com/kirs/) (Evrone Company)
51
+
52
+ ##Feel free for pull requests!
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ class Polemic::BaseController < ApplicationController
2
+
3
+ end
@@ -0,0 +1,38 @@
1
+ class Polemic::CommentsController < Polemic::BaseController
2
+ authorize_resource if defined?(CanCan) == "constant"
3
+
4
+ def create
5
+ @comment = Comment.new(params[:comment])
6
+ @comment.user = current_user
7
+ if @comment.save
8
+ respond_to do |format|
9
+ format.html { redirect_to :back, :notice => I18n.t("polemic.comment.added") }
10
+ end
11
+ else
12
+ respond_to do |format|
13
+ format.html { redirect_to :back, :notice => I18n.t("polemic.comment.has_errors") }
14
+ end
15
+ end
16
+ end
17
+
18
+ # def index
19
+ # @comments = Comment.where(:commentable_id => params[:commentable_id], :commentable_type => params[:commentable_type])
20
+ # respond_to do |format|
21
+ # format.json { render :json => @comments }
22
+ # format.html {
23
+ # render @comments #:partial => "comments/index", :locals => { :comments => @post.comments.includes(:user, :post) }
24
+ # }
25
+ # end
26
+ # end
27
+
28
+ def destroy
29
+ @comment = Comment.find(params[:id])
30
+ if @comment.has_children? # if comment has children, mark as deleted
31
+ @comment.mark_as_deleted!
32
+ else
33
+ @comment.destroy # if no children, destroy it!
34
+ end
35
+
36
+ redirect_to :back, :notice => I18n.t("polemic.comment.removed")
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ class Comment < ActiveRecord::Base
2
+ belongs_to :commentable, :polymorphic => true
3
+ belongs_to :user
4
+ validates :user, :commentable, :body, :presence => true
5
+
6
+ has_ancestry
7
+
8
+ scope :actual, where(:deleted => false)
9
+
10
+ def mark_as_deleted!
11
+ update_attribute(:deleted, true)
12
+ end
13
+ end
@@ -0,0 +1 @@
1
+ <p><b><%= comment.user.name %></b>: <%= comment.body %> @ <%= comment.created_at.strftime("%H:%M %d.%m.%Y") %></p>
@@ -0,0 +1,3 @@
1
+ <h3>Comments: <%= commentable.total_comments %></h3>
2
+ <%= render :partial => "polemic/default/comment", :collection => comments %>
3
+ <%= render :partial => "polemic/default/form", :locals => { :commentable => commentable } %>
@@ -0,0 +1,7 @@
1
+ <%= form_for Comment.new do |f| %>
2
+ <%= f.hidden_field :commentable_id, :value => commentable.id %>
3
+ <%= f.hidden_field :commentable_type, :value => commentable.class %>
4
+ <p><%= f.label :body %></p>
5
+ <p><%= f.text_field :body %></p>
6
+ <p><%= f.submit %></p>
7
+ <% end %>
@@ -0,0 +1,6 @@
1
+ en:
2
+ polemic:
3
+ comment:
4
+ removed: "Successfully removed the comment"
5
+ added: "Successfully added the comment"
6
+ has_errors: "Error occured while saving the comment"
@@ -0,0 +1,6 @@
1
+ ru:
2
+ polemic:
3
+ comment:
4
+ removed: "Комментарий успешно удален."
5
+ added: "Комментарий успешно добавлен."
6
+ has_errors: "Возникли ошибки при добавлении комментария."
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ resources :comments, :except => [:index, :edit, :update], :module => "Polemic"
3
+ end
@@ -0,0 +1,40 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ module Polemic
5
+ module Generators
6
+ class InstallGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+
9
+ source_root File.expand_path("../templates", __FILE__)
10
+
11
+ # desc "Generates migration for Discussion, Message, Speaker and DiscussionView models"
12
+
13
+ def self.orm
14
+ Rails::Generators.options[:rails][:orm]
15
+ end
16
+
17
+ # def self.source_root
18
+ # File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.class.eql?(String)) )
19
+ # end
20
+
21
+ def self.orm_has_migration?
22
+ [:active_record].include? orm
23
+ end
24
+
25
+ def self.next_migration_number(dirname)
26
+ if ActiveRecord::Base.timestamped_migrations
27
+ migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
28
+ migration_number += 1
29
+ migration_number.to_s
30
+ else
31
+ "%.3d" % (current_migration_number(dirname) + 1)
32
+ end
33
+ end
34
+
35
+ def copy_migration
36
+ migration_template 'install.rb', 'db/migrate/install_polemic.rb'
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ class InstallPolemic < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :comments do |t|
4
+ t.references :commentable, :polymorphic => true
5
+ t.text :body
6
+ t.references :user
7
+ t.string :ancestry
8
+ t.boolean :deleted, :default => false
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+
14
+ def self.down
15
+ drop_table :comments
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails/generators'
2
+
3
+ module Polemic
4
+ module Generators
5
+ class ViewsGenerator < Rails::Generators::Base
6
+ source_root File.expand_path('../../../../app/views', __FILE__)
7
+ #class_option :template_engine, :type => :string, :aliases => '-e', :desc => 'Template engine for the views. Available options are "erb" and "haml".'
8
+
9
+ # TODO support of both haml and erb
10
+ def copy_or_fetch
11
+ filename_pattern = File.join self.class.source_root, "*" #/*.html.#{template_engine}"
12
+ Dir.glob(filename_pattern).map {|f| File.basename f}.each do |f|
13
+ directory f.to_s, "app/views/#{f}"
14
+ end
15
+ end
16
+
17
+ # private
18
+
19
+ # def template_engine
20
+ # # options[:template_engine].try(:to_s).try(:downcase) || 'erb'
21
+ # end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ require 'ancestry'
2
+ require "polemic/rails/railtie"
3
+ require "polemic/rails/engine"
4
+ require "polemic/rails/active_record_extension"
5
+ require 'polemic/rails/action_view_extension'
6
+ require "polemic/standart_renderer"
7
+ require "polemic/commentable_methods"
8
+
9
+ module Polemic
10
+
11
+ def self.configure(&block)
12
+ yield @config ||= Polemic::Configuration.new
13
+ end
14
+
15
+ # Global settings for Polemic
16
+ def self.config
17
+ @config
18
+ end
19
+
20
+ # need a Class for 3.0
21
+ class Configuration #:nodoc:
22
+ include ActiveSupport::Configurable
23
+ # config_accessor :user_name
24
+ # config_accessor :faye_host
25
+ # config_accessor :faye_port
26
+ # config_accessor :faye_enabled
27
+
28
+ def param_name
29
+ config.param_name.respond_to?(:call) ? config.param_name.call() : config.param_name
30
+ end
31
+ end
32
+
33
+ # adding method inboxes for models
34
+ ActiveRecord::Base.extend(Polemic::ActiveRecordExtension)
35
+
36
+ end
@@ -0,0 +1,8 @@
1
+ module Polemic
2
+ class Ability
3
+ # include ::CanCan::Ability
4
+
5
+
6
+ end
7
+
8
+ end
@@ -0,0 +1,7 @@
1
+ module Polemic
2
+ module CommentableMethods
3
+ def total_comments
4
+ comments.actual.count
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module Polemic
2
+ module ViewMethods
3
+ def polemic_for(*options)
4
+ commentable_object = options[0]
5
+ raise "You should pass object, for which you want to show comments." unless commentable_object
6
+ @_renderer ||= Polemic::StandardRenderer.new(self)
7
+ @_renderer.render_comments(commentable_object, options[1] || {})
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module Polemic
2
+ module ActiveRecordExtension
3
+ def has_polemic(options = {})
4
+ has_many :comments, :as => :commentable, :dependent => :destroy
5
+ has_many :commentators, :through => :comments, :source => :user
6
+ include Polemic::CommentableMethods
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Polemic
2
+ class Engine < ::Rails::Engine
3
+ # engine_name "polemic"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ require 'rails'
2
+ # require "blah_blah_blah/ability"
3
+
4
+ module Polemic
5
+ class Railtie < ::Rails::Railtie
6
+ config.blah_blah_blah = ActiveSupport::OrderedOptions.new
7
+
8
+ initializer "polemic.configure" do |app|
9
+ Polemic.configure do |config|
10
+ # config.user_name = app.config.inboxes[:user_name] || "email"
11
+ # config.faye_enabled = app.config.inboxes[:faye_enabled] || false
12
+ # config.faye_host = app.config.inboxes[:faye_host] || "localhost"
13
+ # config.faye_port = app.config.inboxes[:faye_port] || "9292"
14
+ end
15
+
16
+ # app.config.middleware.insert_before "::Rails::Rack::Logger", "Inboxes::Middleware"
17
+ end
18
+
19
+ initializer "polemic.action_view" do |app|
20
+ ActionView::Base.send :include, Polemic::ViewMethods
21
+ end
22
+
23
+ # def self.activate
24
+ # Ability.register_ability(InboxesAbility)
25
+ # end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ require 'action_controller'
3
+ require 'action_controller/railtie'
4
+ require 'action_view/railtie'
5
+
6
+ module Polemic
7
+ class StandardRenderer
8
+ include ::ActionView::Context
9
+ # include ActionView::Helpers::UrlHelper
10
+ # include ActionView::Helpers::TagHelper unless self.included_modules.include?(ActionView::Helpers::TagHelper)
11
+
12
+ def initialize(template)
13
+ @template = template
14
+ end
15
+
16
+ # TODO implement logging
17
+ # see https://github.com/amatsuda/kaminari/blob/master/lib/kaminari/helpers/paginator.rb#L76
18
+ def render_comments(commentable, options = {})
19
+ theme = options.delete(:theme) || "default"
20
+ @template.render(:partial => "polemic/#{theme}/comments", :locals => { :comments => commentable.comments.includes(:user), :commentable => commentable })
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Polemic
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "polemic/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "polemic"
7
+ s.version = Polemic::VERSION
8
+ s.authors = ["Kir Shatrov"]
9
+ s.email = ["razor.psp@gmail.com"]
10
+ s.homepage = "http://evrone.com/"
11
+ s.summary = %q{Commentable extension for Rails 3 app}
12
+ s.description = %q{}
13
+
14
+ # s.rubyforge_project = "blah-blah-blah"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "ruby-debug"
23
+ s.add_runtime_dependency "rails"
24
+ s.add_runtime_dependency "ancestry"
25
+ s.add_runtime_dependency "cancan"
26
+ s.add_runtime_dependency "devise"
27
+
28
+ s.add_development_dependency "pg"
29
+ s.add_development_dependency 'rspec', ['>= 0']
30
+ s.add_development_dependency 'factory_girl_rails'
31
+ s.add_development_dependency 'rspec-rails', ['>= 0']
32
+ # s.add_development_dependency 'rr', ['>= 0']
33
+ # s.add_development_dependency 'steak', ['>= 0']
34
+ # s.add_development_dependency 'capybara', ['>= 0']
35
+ # s.add_development_dependency 'database_cleaner', ['>= 0']
36
+ end
@@ -0,0 +1,210 @@
1
+ # Use this hook to configure devise mailer, warden hooks and so forth. The first
2
+ # four configuration values can also be set straight in your models.
3
+ Devise.setup do |config|
4
+ # ==> Mailer Configuration
5
+ # Configure the e-mail address which will be shown in Devise::Mailer,
6
+ # note that it will be overwritten if you use your own mailer class with default "from" parameter.
7
+ config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
8
+
9
+ # Configure the class responsible to send e-mails.
10
+ # config.mailer = "Devise::Mailer"
11
+
12
+ # ==> ORM configuration
13
+ # Load and configure the ORM. Supports :active_record (default) and
14
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
15
+ # available as additional gems.
16
+ require 'devise/orm/active_record'
17
+
18
+ # ==> Configuration for any authentication mechanism
19
+ # Configure which keys are used when authenticating a user. The default is
20
+ # just :email. You can configure it to use [:username, :subdomain], so for
21
+ # authenticating a user, both parameters are required. Remember that those
22
+ # parameters are used only when authenticating and not when retrieving from
23
+ # session. If you need permissions, you should implement that in a before filter.
24
+ # You can also supply a hash where the value is a boolean determining whether
25
+ # or not authentication should be aborted when the value is not present.
26
+ # config.authentication_keys = [ :email ]
27
+
28
+ # Configure parameters from the request object used for authentication. Each entry
29
+ # given should be a request method and it will automatically be passed to the
30
+ # find_for_authentication method and considered in your model lookup. For instance,
31
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
32
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
33
+ # config.request_keys = []
34
+
35
+ # Configure which authentication keys should be case-insensitive.
36
+ # These keys will be downcased upon creating or modifying a user and when used
37
+ # to authenticate or find a user. Default is :email.
38
+ config.case_insensitive_keys = [ :email ]
39
+
40
+ # Configure which authentication keys should have whitespace stripped.
41
+ # These keys will have whitespace before and after removed upon creating or
42
+ # modifying a user and when used to authenticate or find a user. Default is :email.
43
+ config.strip_whitespace_keys = [ :email ]
44
+
45
+ # Tell if authentication through request.params is enabled. True by default.
46
+ # config.params_authenticatable = true
47
+
48
+ # Tell if authentication through HTTP Basic Auth is enabled. False by default.
49
+ # config.http_authenticatable = false
50
+
51
+ # If http headers should be returned for AJAX requests. True by default.
52
+ # config.http_authenticatable_on_xhr = true
53
+
54
+ # The realm used in Http Basic Authentication. "Application" by default.
55
+ # config.http_authentication_realm = "Application"
56
+
57
+ # It will change confirmation, password recovery and other workflows
58
+ # to behave the same regardless if the e-mail provided was right or wrong.
59
+ # Does not affect registerable.
60
+ # config.paranoid = true
61
+
62
+ # ==> Configuration for :database_authenticatable
63
+ # For bcrypt, this is the cost for hashing the password and defaults to 10. If
64
+ # using other encryptors, it sets how many times you want the password re-encrypted.
65
+ #
66
+ # Limiting the stretches to just one in testing will increase the performance of
67
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
68
+ # a value less than 10 in other environments.
69
+ config.stretches = Rails.env.test? ? 1 : 10
70
+
71
+ # Setup a pepper to generate the encrypted password.
72
+ # config.pepper = "9a86f39fcb72573a367c4fcde09b1ae3fe81c3c2c5858c6024033360b39a0f46ab72c8aade6453e96dfae546262c0336372c19518600367fc8b94e9bb4d5db15"
73
+
74
+ # ==> Configuration for :confirmable
75
+ # A period that the user is allowed to access the website even without
76
+ # confirming his account. For instance, if set to 2.days, the user will be
77
+ # able to access the website for two days without confirming his account,
78
+ # access will be blocked just in the third day. Default is 0.days, meaning
79
+ # the user cannot access the website without confirming his account.
80
+ # config.confirm_within = 2.days
81
+
82
+ # Defines which key will be used when confirming an account
83
+ # config.confirmation_keys = [ :email ]
84
+
85
+ # ==> Configuration for :rememberable
86
+ # The time the user will be remembered without asking for credentials again.
87
+ # config.remember_for = 2.weeks
88
+
89
+ # If true, a valid remember token can be re-used between multiple browsers.
90
+ # config.remember_across_browsers = true
91
+
92
+ # If true, extends the user's remember period when remembered via cookie.
93
+ # config.extend_remember_period = false
94
+
95
+ # If true, uses the password salt as remember token. This should be turned
96
+ # to false if you are not using database authenticatable.
97
+ config.use_salt_as_remember_token = true
98
+
99
+ # Options to be passed to the created cookie. For instance, you can set
100
+ # :secure => true in order to force SSL only cookies.
101
+ # config.cookie_options = {}
102
+
103
+ # ==> Configuration for :validatable
104
+ # Range for password length. Default is 6..128.
105
+ # config.password_length = 6..128
106
+
107
+ # Email regex used to validate email formats. It simply asserts that
108
+ # an one (and only one) @ exists in the given string. This is mainly
109
+ # to give user feedback and not to assert the e-mail validity.
110
+ # config.email_regexp = /\A[^@]+@[^@]+\z/
111
+
112
+ # ==> Configuration for :timeoutable
113
+ # The time you want to timeout the user session without activity. After this
114
+ # time the user will be asked for credentials again. Default is 30 minutes.
115
+ # config.timeout_in = 30.minutes
116
+
117
+ # ==> Configuration for :lockable
118
+ # Defines which strategy will be used to lock an account.
119
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
120
+ # :none = No lock strategy. You should handle locking by yourself.
121
+ # config.lock_strategy = :failed_attempts
122
+
123
+ # Defines which key will be used when locking and unlocking an account
124
+ # config.unlock_keys = [ :email ]
125
+
126
+ # Defines which strategy will be used to unlock an account.
127
+ # :email = Sends an unlock link to the user email
128
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
129
+ # :both = Enables both strategies
130
+ # :none = No unlock strategy. You should handle unlocking by yourself.
131
+ # config.unlock_strategy = :both
132
+
133
+ # Number of authentication tries before locking an account if lock_strategy
134
+ # is failed attempts.
135
+ # config.maximum_attempts = 20
136
+
137
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
138
+ # config.unlock_in = 1.hour
139
+
140
+ # ==> Configuration for :recoverable
141
+ #
142
+ # Defines which key will be used when recovering the password for an account
143
+ # config.reset_password_keys = [ :email ]
144
+
145
+ # Time interval you can reset your password with a reset password key.
146
+ # Don't put a too small interval or your users won't have the time to
147
+ # change their passwords.
148
+ config.reset_password_within = 6.hours
149
+
150
+ # ==> Configuration for :encryptable
151
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
152
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
153
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
154
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
155
+ # REST_AUTH_SITE_KEY to pepper)
156
+ # config.encryptor = :sha512
157
+
158
+ # ==> Configuration for :token_authenticatable
159
+ # Defines name of the authentication token params key
160
+ # config.token_authentication_key = :auth_token
161
+
162
+ # If true, authentication through token does not store user in session and needs
163
+ # to be supplied on each request. Useful if you are using the token as API token.
164
+ # config.stateless_token = false
165
+
166
+ # ==> Scopes configuration
167
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
168
+ # "users/sessions/new". It's turned off by default because it's slower if you
169
+ # are using only default views.
170
+ # config.scoped_views = false
171
+
172
+ # Configure the default scope given to Warden. By default it's the first
173
+ # devise role declared in your routes (usually :user).
174
+ # config.default_scope = :user
175
+
176
+ # Configure sign_out behavior.
177
+ # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
178
+ # The default is true, which means any logout action will sign out all active scopes.
179
+ # config.sign_out_all_scopes = true
180
+
181
+ # ==> Navigation configuration
182
+ # Lists the formats that should be treated as navigational. Formats like
183
+ # :html, should redirect to the sign in page when the user does not have
184
+ # access, but formats like :xml or :json, should return 401.
185
+ #
186
+ # If you have any extra navigational formats, like :iphone or :mobile, you
187
+ # should add them to the navigational formats lists.
188
+ #
189
+ # The :"*/*" and "*/*" formats below is required to match Internet
190
+ # Explorer requests.
191
+ # config.navigational_formats = [:"*/*", "*/*", :html]
192
+
193
+ # The default HTTP method used to sign out a resource. Default is :delete.
194
+ config.sign_out_via = :delete
195
+
196
+ # ==> OmniAuth
197
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
198
+ # up on your models and hooks.
199
+ # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
200
+
201
+ # ==> Warden configuration
202
+ # If you want to use other strategies, that are not supported by Devise, or
203
+ # change the failure app, you can configure them inside the config.warden block.
204
+ #
205
+ # config.warden do |manager|
206
+ # manager.failure_app = AnotherApp
207
+ # manager.intercept_401 = false
208
+ # manager.default_strategies(:scope => :user).unshift :some_external_strategy
209
+ # end
210
+ end
@@ -0,0 +1,100 @@
1
+ require 'active_record'
2
+ require 'action_controller'
3
+ require 'action_controller/railtie'
4
+ require 'action_view/railtie'
5
+ require 'action_view/context'
6
+
7
+ require "cancan"
8
+ require "cancan/ability"
9
+ require "cancan/controller_resource"
10
+ require "cancan/controller_additions"
11
+
12
+ require 'devise'
13
+ require 'devise/orm/active_record'
14
+
15
+ # database
16
+ ActiveRecord::Base.configurations = {'test' => {:adapter => 'postgresql', :database => 'polemic_test', :username => "postgres"}}
17
+ ActiveRecord::Base.establish_connection('test')
18
+
19
+ require 'devise_config'
20
+
21
+ # config
22
+ app = Class.new(Rails::Application)
23
+ app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
24
+ app.config.session_store :cookie_store, :key => "_myapp_session"
25
+ app.config.active_support.deprecation = :log
26
+ app.initialize!
27
+
28
+ # models
29
+ class User < ActiveRecord::Base
30
+ devise :database_authenticatable, :registerable,
31
+ :recoverable, :rememberable, :trackable, :validatable
32
+ attr_accessible :email, :password, :password_confirmation, :remember_me, :name
33
+ validates :name, :presence => true
34
+ end
35
+
36
+ class Post < ActiveRecord::Base
37
+ validates :title, :user, :body, :presence => true
38
+ has_polemic
39
+ belongs_to :user
40
+ end
41
+
42
+ # routes
43
+ app.routes.draw do
44
+ devise_for :users
45
+ end
46
+
47
+ #migrations
48
+ ActiveRecord::Base.silence do
49
+ ActiveRecord::Migration.verbose = false
50
+ ActiveRecord::Schema.define :version => 0 do
51
+ create_table "users", :force => true do |t|
52
+ t.string "email", :default => "", :null => false
53
+ t.string "encrypted_password", :limit => 128, :default => "", :null => false
54
+ t.string "reset_password_token"
55
+ t.datetime "reset_password_sent_at"
56
+ t.datetime "remember_created_at"
57
+ t.integer "sign_in_count", :default => 0
58
+ t.datetime "current_sign_in_at"
59
+ t.datetime "last_sign_in_at"
60
+ t.string "current_sign_in_ip"
61
+ t.string "last_sign_in_ip"
62
+ t.datetime "created_at"
63
+ t.datetime "updated_at"
64
+ t.string "name"
65
+ end
66
+
67
+ create_table "comments", :force => true do |t|
68
+ t.integer "commentable_id"
69
+ t.string "commentable_type"
70
+ t.text "body"
71
+ t.integer "user_id"
72
+ t.string "ancestry"
73
+ t.boolean "deleted", :default => false
74
+ t.datetime "created_at", :null => false
75
+ t.datetime "updated_at", :null => false
76
+ end
77
+
78
+ create_table "posts", :force => true do |t|
79
+ t.string "title"
80
+ t.text "body"
81
+ t.integer "user_id"
82
+ t.datetime "created_at", :null => false
83
+ t.datetime "updated_at", :null => false
84
+ end
85
+ end
86
+ end
87
+
88
+ # controllers
89
+ class ApplicationController < ActionController::Base
90
+ before_filter :assign_unread_discussions
91
+
92
+ private
93
+
94
+ def assign_unread_discussions
95
+ @unread_discussions_count = Discussion.unread_for(current_user).count if user_signed_in?
96
+ end
97
+ end
98
+
99
+ # helpers
100
+ Object.const_set(:ApplicationHelper, Module.new)
@@ -0,0 +1,6 @@
1
+ # Simulate a gem providing a subclass of ActiveRecord::Base before the Railtie is loaded.
2
+
3
+ require 'active_record'
4
+
5
+ class GemDefinedModel < ActiveRecord::Base
6
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe Comment do
4
+ it "has mark_as_deleted! method" do
5
+ comment = Comment.new
6
+ comment.respond_to?("mark_as_deleted!").should be_true
7
+ end
8
+
9
+ it "mark_as_deleted! should mark comment as deleted" do
10
+ comment = Factory(:comment)
11
+ comment.mark_as_deleted!
12
+ comment.deleted.should be_true
13
+ end
14
+
15
+ it "actual comments should not include deleted comments" do
16
+ 2.times do
17
+ Factory(:comment)
18
+ end
19
+ deleted_comment = Factory(:comment)
20
+ deleted_comment.mark_as_deleted!
21
+ Comment.actual.should_not include deleted_comment
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Polemic::CommentsController do
4
+
5
+ # render_views
6
+
7
+ # it "should render create method" do
8
+ # post = Factory(:post)
9
+ # post(:create, :commentable => post)
10
+ # end
11
+ end
File without changes
@@ -0,0 +1,32 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rails'
4
+ require 'active_record'
5
+ require 'polemic'
6
+ require 'rspec/rails'
7
+ require 'factory_girl'
8
+ # require 'database_cleaner'
9
+ # Ensure we use 'syck' instead of 'psych' in 1.9.2
10
+ # RubyGems >= 1.5.0 uses 'psych' on 1.9.2, but
11
+ # Psych does not yet support YAML 1.1 merge keys.
12
+ # Merge keys is often used in mongoid.yml
13
+ # See: http://redmine.ruby-lang.org/issues/show/4300
14
+ if RUBY_VERSION >= '1.9.2'
15
+ YAML::ENGINE.yamler = 'syck'
16
+ end
17
+ # require 'fake_gem'
18
+ require 'fake_app'
19
+
20
+ # Requires supporting files with custom matchers and macros, etc,
21
+ # in ./support/ and its subdirectories.
22
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
23
+
24
+ RSpec.configure do |config|
25
+ config.include Devise::TestHelpers, :type => :controller
26
+ config.color_enabled = true
27
+ # config.mock_with :rr
28
+ # config.before :all do
29
+ # # ActiveRecord::Base.connection.execute 'CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255))' unless ActiveRecord::Base.connection.table_exists? 'users'
30
+ # # CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'users'
31
+ # end
32
+ end
@@ -0,0 +1,22 @@
1
+ FactoryGirl.define do
2
+
3
+ factory :comment do
4
+ commentable { Factory(:post) }
5
+ user { Factory(:user) }
6
+ body 'comment body'
7
+ end
8
+
9
+ factory :post do
10
+ user { Factory(:user) }
11
+ title 'post title'
12
+ body 'post body'
13
+ end
14
+
15
+ factory :user do |n|
16
+ name "Test User"
17
+ email { Factory.next(:email) }
18
+ password "password"
19
+ password_confirmation "password"
20
+ end
21
+
22
+ end
@@ -0,0 +1,3 @@
1
+ Factory.sequence :email do |n|
2
+ "email#{n}@example.com"
3
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: polemic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kir Shatrov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-29 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70178662691980 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70178662691980
25
+ - !ruby/object:Gem::Dependency
26
+ name: ancestry
27
+ requirement: &70178662691080 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70178662691080
36
+ - !ruby/object:Gem::Dependency
37
+ name: cancan
38
+ requirement: &70178662690380 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70178662690380
47
+ - !ruby/object:Gem::Dependency
48
+ name: devise
49
+ requirement: &70178662689460 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70178662689460
58
+ - !ruby/object:Gem::Dependency
59
+ name: pg
60
+ requirement: &70178662688440 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70178662688440
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: &70178662686980 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70178662686980
80
+ - !ruby/object:Gem::Dependency
81
+ name: factory_girl_rails
82
+ requirement: &70178662685560 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70178662685560
91
+ - !ruby/object:Gem::Dependency
92
+ name: rspec-rails
93
+ requirement: &70178662664360 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70178662664360
102
+ description: ''
103
+ email:
104
+ - razor.psp@gmail.com
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - .gitignore
110
+ - .travis.yml
111
+ - Gemfile
112
+ - README.md
113
+ - Rakefile
114
+ - app/controllers/polemic/base_controller.rb
115
+ - app/controllers/polemic/comments_controller.rb
116
+ - app/models/comment.rb
117
+ - app/views/polemic/default/_comment.html.erb
118
+ - app/views/polemic/default/_comments.html.erb
119
+ - app/views/polemic/default/_form.html.erb
120
+ - config/locales/en.yml
121
+ - config/locales/ru.yml
122
+ - config/routes.rb
123
+ - lib/generators/polemic/install_generator.rb
124
+ - lib/generators/polemic/templates/install.rb
125
+ - lib/generators/polemic/views_generator.rb
126
+ - lib/polemic.rb
127
+ - lib/polemic/ability.rb
128
+ - lib/polemic/commentable_methods.rb
129
+ - lib/polemic/rails/action_view_extension.rb
130
+ - lib/polemic/rails/active_record_extension.rb
131
+ - lib/polemic/rails/engine.rb
132
+ - lib/polemic/rails/railtie.rb
133
+ - lib/polemic/standart_renderer.rb
134
+ - lib/polemic/version.rb
135
+ - polemic.gemspec
136
+ - spec/devise_config.rb
137
+ - spec/fake_app.rb
138
+ - spec/fake_gem.rb
139
+ - spec/polemic/comment_spec.rb
140
+ - spec/polemic/polemic_comments_controller_spec.rb
141
+ - spec/polemic_spec.rb
142
+ - spec/spec_helper.rb
143
+ - spec/support/factories.rb
144
+ - spec/support/sequences.rb
145
+ homepage: http://evrone.com/
146
+ licenses: []
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ! '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 1.8.10
166
+ signing_key:
167
+ specification_version: 3
168
+ summary: Commentable extension for Rails 3 app
169
+ test_files:
170
+ - spec/devise_config.rb
171
+ - spec/fake_app.rb
172
+ - spec/fake_gem.rb
173
+ - spec/polemic/comment_spec.rb
174
+ - spec/polemic/polemic_comments_controller_spec.rb
175
+ - spec/polemic_spec.rb
176
+ - spec/spec_helper.rb
177
+ - spec/support/factories.rb
178
+ - spec/support/sequences.rb