17 |
--------------------------------------------------------------------------------
/.github/stale.yml:
--------------------------------------------------------------------------------
1 | # Number of days of inactivity before an issue becomes stale
2 | daysUntilStale: 60
3 | # Number of days of inactivity before a stale issue is closed
4 | daysUntilClose: 7
5 | # Issues with these labels will never be considered stale
6 | exemptLabels:
7 | - pinned
8 | - security
9 | # Label to use when marking an issue as stale
10 | staleLabel: wontfix
11 | # Comment to post when marking an issue as stale. Set to `false` to disable
12 | markComment: >
13 | This issue has been automatically marked as stale because it has not had
14 | recent activity. It will be closed if no further activity occurs. Thank you
15 | for your contributions.
16 | # Comment to post when closing a stale issue. Set to `false` to disable
17 | closeComment: false
--------------------------------------------------------------------------------
/lib/acts_as_commentable/commentable_methods.rb:
--------------------------------------------------------------------------------
1 | require 'active_record'
2 |
3 | # ActsAsCommentable
4 | module Juixe
5 | module Acts
6 | module Commentable
7 | extend ActiveSupport::Concern
8 |
9 | class_methods do
10 | def acts_as_commentable(*args)
11 | options = args.to_a.flatten.compact.partition { |opt| opt.kind_of? Hash }
12 |
13 | join_options = options.first.blank? ? [{}] : options.first
14 | throw "Only one set of options can be supplied for the join" if join_options.length > 1
15 | join_options = join_options.first
16 |
17 | has_many :comments,
18 | **{ as: :commentable, dependent: :destroy }.merge(join_options)
19 | end
20 | end
21 |
22 | ActiveRecord::Base.include self
23 | end
24 | end
25 | end
26 |
--------------------------------------------------------------------------------
/lib/generators/solidus_comments/install/install_generator.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module SolidusComments
4 | module Generators
5 | class InstallGenerator < Rails::Generators::Base
6 | class_option :auto_run_migrations, type: :boolean, default: false
7 |
8 | def add_migrations
9 | run 'bundle exec rake railties:install:migrations FROM=solidus_comments'
10 | end
11 |
12 | def run_migrations
13 | run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
14 | if run_migrations
15 | run 'bundle exec rake db:migrate'
16 | else
17 | puts 'Skipping rake db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
18 | end
19 | end
20 | end
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Configure Rails Environment
4 | ENV['RAILS_ENV'] = 'test'
5 |
6 | # Run Coverage report
7 | require 'solidus_dev_support/rspec/coverage'
8 |
9 | require File.expand_path('dummy/config/environment.rb', __dir__)
10 |
11 | # Requires factories and other useful helpers defined in spree_core.
12 | require 'solidus_dev_support/rspec/feature_helper'
13 |
14 | # Requires supporting ruby files with custom matchers and macros, etc,
15 | # in spec/support/ and its subdirectories.
16 | Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
17 |
18 | SolidusDevSupport::TestingSupport::Factories.load_for(SolidusComments::Engine)
19 |
20 | RSpec.configure do |config|
21 | config.infer_spec_type_from_file_location!
22 | config.use_transactional_fixtures = false
23 | end
24 |
--------------------------------------------------------------------------------
/app/views/spree/admin/comment_types/new.html.erb:
--------------------------------------------------------------------------------
1 | <%= render :partial => 'spree/admin/shared/configuration_menu' %>
2 |
3 | <% content_for :page_title do %>
4 | <%= I18n.t('spree.new_comment_type') %>
5 | <% end %>
6 |
7 | <% content_for :page_actions do %>
8 |
27 |
--------------------------------------------------------------------------------
/lib/acts_as_commentable/MIT-LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2006 Cosmin Radoi
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Solidus Comments
2 | ==============
3 |
4 | [](https://circleci.com/gh/solidusio-contrib/solidus_comments)
5 |
6 | Solidus Comments is an extension for Solidus to allow commenting on different models via the
7 | admin ui and currently supports Orders & Shipments.
8 |
9 | Solidus Comments also supports optional comment Types which can be defined per comment-able
10 | object (i.e. Order, Shipment, etc) via the admin Configuration tab.
11 |
12 | This is based on a fork / rename of jderrett/spree-order-comments, and subsequently spree/spree-comments
13 |
14 | Notes:
15 |
16 | * Comments are create-only. You cannot edit or remove them from the Admin UI.
17 |
18 | Installation
19 | ------------
20 |
21 | Add the following to your Gemfile (or check Versionfile for Solidus versions requirements):
22 |
23 | gem "solidus_comments"
24 |
25 | Run:
26 |
27 | ```shell
28 | bundle install
29 | bundle exec rails g solidus_comments:install
30 | ```
31 |
32 | Run the migrations if you did not during the installation generator:
33 |
34 | bundle exec rake db:migrate
35 |
36 | Start your server:
37 |
38 | rails s
39 |
--------------------------------------------------------------------------------
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2.1
2 |
3 | orbs:
4 | browser-tools: circleci/browser-tools@1.4
5 |
6 | # Always take the latest version of the orb, this allows us to
7 | # run specs against Solidus supported versions only without the need
8 | # to change this configuration every time a Solidus version is released
9 | # or goes EOL.
10 | solidusio_extensions: solidusio/extensions@volatile
11 |
12 | jobs:
13 | run-specs-with-postgres:
14 | executor: solidusio_extensions/postgres
15 | steps:
16 | - browser-tools/install-chrome:
17 | chrome-version: 123.0.6312.105
18 | replace-existing: true
19 | - solidusio_extensions/run-tests
20 | run-specs-with-mysql:
21 | executor: solidusio_extensions/mysql
22 | steps:
23 | - browser-tools/install-chrome:
24 | chrome-version: 123.0.6312.105
25 | replace-existing: true
26 | - solidusio_extensions/run-tests
27 |
28 | workflows:
29 | "Run specs on supported Solidus versions":
30 | jobs:
31 | - run-specs-with-postgres
32 | - run-specs-with-mysql
33 | "Weekly run specs against master":
34 | triggers:
35 | - schedule:
36 | cron: "0 0 * * 4" # every Thursday
37 | filters:
38 | branches:
39 | only:
40 | - master
41 | jobs:
42 | - run-specs-with-postgres
43 | - run-specs-with-mysql
44 |
--------------------------------------------------------------------------------
/solidus_comments.gemspec:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | $:.push File.expand_path('lib', __dir__)
4 | require 'solidus_comments/version'
5 |
6 | Gem::Specification.new do |s|
7 | s.name = 'solidus_comments'
8 | s.version = SolidusComments::VERSION
9 | s.summary = 'Adds comments to the solidus admin'
10 | s.license = 'BSD-3-Clause'
11 |
12 | s.author = ['Rails Dog', 'Solidus Contrib']
13 | s.email = 'contact@solidus.io'
14 | s.homepage = 'https://github.com/solidusio-contrib/solidus_comments'
15 |
16 | if s.respond_to?(:metadata)
17 | s.metadata["homepage_uri"] = s.homepage if s.homepage
18 | s.metadata["source_code_uri"] = s.homepage if s.homepage
19 | end
20 |
21 | s.required_ruby_version = '>= 2.5'
22 |
23 | s.files = Dir.chdir(File.expand_path(__dir__)) do
24 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25 | end
26 | s.test_files = Dir['spec/**/*']
27 | s.bindir = "exe"
28 | s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
29 | s.require_paths = ["lib"]
30 |
31 | s.add_dependency 'deface', '~> 1.5'
32 | s.add_dependency 'solidus_core', ['>= 2.0.0', '< 5']
33 | s.add_dependency 'solidus_backend', ['>= 2.0.0', '< 5']
34 | s.add_dependency 'solidus_support', '~> 0.5'
35 |
36 | s.add_development_dependency 'solidus_dev_support'
37 | s.add_development_dependency 'shoulda-matchers', '~> 4.0'
38 | end
39 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011 Rails Dog
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification,
5 | are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright notice,
8 | this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above copyright notice,
10 | this list of conditions and the following disclaimer in the documentation
11 | and/or other materials provided with the distribution.
12 | * Neither the name Solidus nor the names of its contributors may be used to
13 | endorse or promote products derived from this software without specific
14 | prior written permission.
15 |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 |
--------------------------------------------------------------------------------
/spec/model/spree/comment_spec.rb:
--------------------------------------------------------------------------------
1 | require "spec_helper"
2 |
3 | RSpec.describe Spree::Comment do
4 | let(:commentable) { create :shipment }
5 | let(:user) { create :admin_user }
6 |
7 | let!(:older_comment) {
8 | comment = described_class.create! comment: "Text",
9 | commentable: commentable,
10 | user: user
11 | comment.update_column :created_at, 10.days.ago
12 | comment
13 | }
14 | let!(:newer_comment) {
15 | comment = described_class.create! comment: "Text",
16 | commentable: commentable,
17 | user: user
18 | comment.update_column :created_at, 1.minute.ago
19 | comment
20 | }
21 |
22 | describe ".all" do
23 | subject { described_class.all }
24 |
25 | it "returns comments in chronological order" do
26 | expect(subject).to eq [older_comment, newer_comment]
27 | end
28 | end
29 |
30 | describe ".recent" do
31 | subject { described_class.recent }
32 |
33 | it "returns comments in reverse-chronological order" do
34 | expect(subject).to eq [newer_comment, older_comment]
35 | end
36 | end
37 |
38 | describe "#valid?" do
39 | subject { comment.valid? }
40 |
41 | context "when the comment is empty" do
42 | let(:comment) {
43 | described_class.new comment: nil,
44 | commentable: commentable,
45 | user: user
46 | }
47 |
48 | it { is_expected.to eq false }
49 | end
50 |
51 | context "when the comment has text" do
52 | let(:comment) {
53 | described_class.new comment: "Text",
54 | commentable: commentable,
55 | user: user
56 | }
57 |
58 | it { is_expected.to eq true }
59 | end
60 | end
61 | end
62 |
--------------------------------------------------------------------------------
/app/views/spree/admin/comment_types/index.html.erb:
--------------------------------------------------------------------------------
1 | <%= render :partial => 'spree/admin/shared/configuration_menu' %>
2 |
3 | <% content_for :page_title do %>
4 | <%= I18n.t('spree.comment_types') %>
5 | <% end %>
6 |
7 | <% content_for :page_actions do %>
8 |