Skip to content

Commit

Permalink
Rails 3.1 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Trung Lê committed Sep 21, 2011
1 parent 82cc21a commit 3c524f9
Show file tree
Hide file tree
Showing 20 changed files with 169 additions and 155 deletions.
32 changes: 0 additions & 32 deletions Gemfile

This file was deleted.

26 changes: 26 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2011 Rails Dog
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name Spree nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 changes: 6 additions & 5 deletions README.markdown → README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Spree Comments
Spree Comments
==============

Spree Comments is an extension for Spree to allow commenting on different models via the
admin ui and currently supports Orders & Shipments.
Expand All @@ -25,17 +26,17 @@ Add the following to your Gemfile
gem "spree_comments"
gem "acts_as_commentable"

Run:
Run:

bundle install

Copy over migrations via the rake task:

rake spree_comments:install
bundle exec rake railties:install:migrations FROM=spree_comments

Run the migrations:

rake db:migrate
bundle exec rake db:migrate

Start your server:

Expand Down
78 changes: 20 additions & 58 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,69 +1,31 @@
# encoding: utf-8
require 'rubygems'
require 'rake'
require 'rake/testtask'
require 'rake/packagetask'
require 'rubygems/package_task'
require 'rspec/core/rake_task'
require 'cucumber/rake/task'
require 'spree_core/testing_support/common_rake'

desc "Default Task"
task :default => [ :spec ]
RSpec::Core::RakeTask.new
Cucumber::Rake::Task.new

gemfile = File.expand_path('../spec/test_app/Gemfile', __FILE__)
if File.exists?(gemfile) && %w(rcov spec cucumber).include?(ARGV.first.to_s)
require 'bundler'
ENV['BUNDLE_GEMFILE'] = gemfile
Bundler.setup
task :default => [:spec, :cucumber ]

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new

require 'cucumber/rake/task'
Cucumber::Rake::Task.new do |t|
t.cucumber_opts = %w{--format pretty}
end

desc "Run specs with RCov"
RSpec::Core::RakeTask.new(:rcov) do |t|
t.rcov = true
t.rcov_opts = %w{ --exclude gems\/,spec\/,features\/}
t.verbose = true
end
spec = eval(File.read('spree_comments.gemspec'))

Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end

desc "Regenerates a rails 3 app for testing"
task :test_app do
SPREE_PATH = ENV['SPREE_PATH']
raise "SPREE_PATH should be specified" unless SPREE_PATH
require File.join(SPREE_PATH, 'lib/generators/spree/test_app_generator')
class AuthTestAppGenerator < Spree::Generators::TestAppGenerator
def tweak_gemfile
append_file 'Gemfile' do
<<-gems
gem 'spree_core', :path => '#{File.join(SPREE_PATH, 'core')}'
gem 'spree_auth', :path => '#{File.join(SPREE_PATH, 'auth')}'
gem 'spree_comments', :path => '#{File.dirname(__FILE__)}'
gems
end
end

def install_gems
inside "test_app" do
run 'rake spree_core:install'
run 'rake spree_auth:install'
run 'rake spree_comments:install'
end
end

def migrate_db
run_migrations
end
end
AuthTestAppGenerator.start
desc "Release to gemcutter"
task :release => :package do
require 'rake/gemcutter'
Rake::Gemcutter::Tasks.new(spec).define
Rake::Task['gem:push'].invoke
end

namespace :test_app do
desc 'Rebuild test and cucumber databases'
task :rebuild_dbs do
system("cd spec/test_app && rake db:drop db:migrate RAILS_ENV=test && rake db:drop db:migrate RAILS_ENV=cucumber")
end
desc "Generates a dummy app for testing"
task :test_app do
ENV['LIB_NAME'] = 'spree_comments'
Rake::Task['common:test_app'].invoke
end

5 changes: 5 additions & 0 deletions app/overrides/add_comment_configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Deface::Override.new(:virtual_path => "admin/configurations/index",
:name => "converted_admin_configurations_menu_468573024",
:insert_after => "[data-hook='admin_configurations_menu'], #admin_configurations_menu[data-hook]",
:text => "<%= configurations_menu_item(I18n.t('comment_types'), admin_comment_types_url, I18n.t('manage_comment_types')) %>",
:disabled => false)
5 changes: 5 additions & 0 deletions app/overrides/add_comment_to_admin_orders_tabs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Deface::Override.new(:virtual_path => "admin/shared/_order_tabs",
:name => "converted_admin_order_tabs_472794197",
:insert_bottom => "[data-hook='admin_order_tabs'], #admin_order_tabs[data-hook]",
:partial => "admin/orders/tab",
:disabled => false)
5 changes: 5 additions & 0 deletions app/overrides/add_shipment_comment_button.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Deface::Override.new(:virtual_path => "admin/shipments/edit",
:name => "converted_admin_shipment_edit_buttons_233418828",
:insert_after => "[data-hook='admin_shipment_edit_buttons'], #admin_shipment_edit_buttons[data-hook]",
:partial => "admin/shipments/button",
:disabled => false)
2 changes: 1 addition & 1 deletion app/views/admin/orders/_tab.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<li <%= raw ' class="active"' if (defined? current and current == 'Comments') %>>
<li <%== ' class="active"' if (defined? current and current == 'Comments') %>>
<%= link_to t(:comments), comments_admin_order_url(@order) %>
</li>
2 changes: 1 addition & 1 deletion app/views/admin/shared/_comment_list.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<table class="index">
<tr>
<th style="width:140px;"><%= "#{I18n::t('spree.date')}/#{I18n::t('spree.time')}" %></th>
<th style="width:140px;"><%= "#{t('spree.date')}/#{t('spree.time')}" %></th>
<% if @comment_types and !@comment_types.empty? %>
<th><%= t(:type) %></th>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/shipments/_button.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<li>
<%= button_link_to(t(:comments), comments_admin_order_shipment_url(@order, @shipment)) %>
<%= button_link_to t(:comments), comments_admin_order_shipment_url(@order, @shipment) %>
</li>

1 change: 1 addition & 0 deletions db/migrate/20091021182639_create_comments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def self.up
t.text :comment, :default => ""
t.references :commentable, :polymorphic => true
t.references :user

t.timestamps
end

Expand Down
1 change: 1 addition & 0 deletions db/migrate/20100406085611_create_comment_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ def self.up
create_table :comment_types do |t|
t.string :name
t.string :applies_to

t.timestamps
end
end
Expand Down
19 changes: 19 additions & 0 deletions lib/generators/spree_comments/install/install_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module SpreeComments
module Generators
class InstallGenerator < Rails::Generators::Base

def add_migrations
run 'bundle exec rake railties:install:migrations FROM=spree_comments'
end

def run_migrations
res = ask "Would you like to run the migrations now? [Y/n]"
if res == "" || res.downcase == "y"
run 'bundle exec rake db:migrate'
else
puts "Skiping rake db:migrate, don't forget to run it!"
end
end
end
end
end
17 changes: 1 addition & 16 deletions lib/spree_comments.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
require 'spree_core'
require 'acts_as_commentable'
require 'spree_comments_hooks'

module SpreeComments
class Engine < Rails::Engine

config.autoload_paths += %W(#{config.root}/lib)

def self.activate
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
Rails.env.production? ? require(c) : load(c)
end
end

config.to_prepare &method(:activate).to_proc
end
end
require 'spree_comments/engine'
25 changes: 25 additions & 0 deletions lib/spree_comments/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module SpreeComments
class Engine < Rails::Engine
engine_name 'spree_comments'

config.autoload_paths += %W(#{config.root}/lib)

# use rspec for tests
config.generators do |g|
g.test_framework :rspec
end

def self.activate
Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
Rails.application.config.cache_classes ? require(c) : load(c)
end

Dir.glob(File.join(File.dirname(__FILE__), "../../app/overrides/*.rb")) do |c|
Rails.application.config.cache_classes ? require(c) : load(c)
end
end

config.to_prepare &method(:activate).to_proc
end
end

19 changes: 0 additions & 19 deletions lib/spree_comments_hooks.rb

This file was deleted.

15 changes: 0 additions & 15 deletions lib/tasks/install.rake

This file was deleted.

9 changes: 9 additions & 0 deletions script/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.


ENGINE_PATH = File.expand_path('../..', __FILE__)
APP_PATH = File.expand_path('../../../config/application', __FILE__)
require File.expand_path('../../../config/boot', __FILE__)
require 'rails/commands'

31 changes: 31 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Configure Rails Environment
ENV["RAILS_ENV"] = "test"


require File.expand_path("../../../config/environment.rb", __FILE__)


require 'rspec/rails'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
end
Loading

0 comments on commit 3c524f9

Please sign in to comment.