From 4634ab81a6d7747cc267e46197f4d5c650259ff3 Mon Sep 17 00:00:00 2001 From: jbbarth Date: Fri, 24 Aug 2012 16:59:04 +0200 Subject: [PATCH 01/15] Remove deprecated RAILS_* constants --- rails/init.rb | 2 +- spec/spec_helper.rb | 2 +- writeup.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rails/init.rb b/rails/init.rb index d06fb5c..ae2abd1 100644 --- a/rails/init.rb +++ b/rails/init.rb @@ -1,7 +1,7 @@ # Redmine customer plugin require 'redmine' -RAILS_DEFAULT_LOGGER.info 'Starting Customer plugin for RedMine' +Rails.logger.info 'Starting Customer plugin for RedMine' Redmine::Plugin.register :customer_plugin do name 'Customer plugin' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a9244a7..b2da044 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,7 +15,7 @@ # in your config/boot.rb config.use_transactional_fixtures = true config.use_instantiated_fixtures = false - config.fixture_path = RAILS_ROOT + '/spec/fixtures/' + config.fixture_path = Rails.root + '/spec/fixtures/' # == Fixtures # diff --git a/writeup.txt b/writeup.txt index 276fa34..0f251aa 100644 --- a/writeup.txt +++ b/writeup.txt @@ -22,7 +22,7 @@ # Redmine customer plugin require 'redmine' -RAILS_DEFAULT_LOGGER.info 'Starting Customer plugin for RedMine' +Rails.logger.info 'Starting Customer plugin for RedMine' Redmine::Plugin.register :customer do name 'Customer plugin' From 5ed1236097582a756aedab70349ccfcd5db57557 Mon Sep 17 00:00:00 2001 From: jbbarth Date: Fri, 24 Aug 2012 17:19:26 +0200 Subject: [PATCH 02/15] Updated README --- README.rdoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rdoc b/README.rdoc index 5284b9f..0490216 100644 --- a/README.rdoc +++ b/README.rdoc @@ -15,7 +15,7 @@ A copy of the released version can be downloaded from {Little Stream Software}[h == Install -1. Follow the Redmine plugin installation steps at: http://www.redmine.org/wiki/redmine/Plugins Make sure the plugin is installed to +vendor/plugins/customer_plugin+ +1. Follow the Redmine plugin installation steps at: http://www.redmine.org/wiki/redmine/Plugins Make sure the plugin is installed to +plugins/customer_plugin+ 2. Setup the database using the migrations. +rake db:migrate_plugins+ 3. Login to your Redmine install as an Administrator 4. Setup the permissions for your roles @@ -33,12 +33,12 @@ A copy of the released version can be downloaded from {Little Stream Software}[h === Zip file 1. Download the latest zip file from https://projects.littlestreamsoftware.com -2. Unzip the file to your Redmine into vendor/plugins +2. Unzip the file to your Redmine into plugins/ 3. Restart your Redmine === Git -1. Open a shell to your Redmine's vendor/plugins/customer_plugin folder +1. Open a shell to your Redmine's plugins/customer_plugin folder 2. Update your git copy with +git pull+ 3. Restart your Redmine From 6271a650f79b24d300b4cfcdebfa288ea36f3035 Mon Sep 17 00:00:00 2001 From: jbbarth Date: Fri, 24 Aug 2012 17:34:19 +0200 Subject: [PATCH 03/15] Upgraded spec_helper for new plugins location --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b2da044..df94151 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,7 +3,7 @@ ENV["RAILS_ENV"] = "test" # Allows loading of an environment config based on the environment -redmine_root = ENV["REDMINE_ROOT"] || File.dirname(__FILE__) + "/../../../.." +redmine_root = ENV["REDMINE_ROOT"] || File.dirname(__FILE__) + "/../../.." require File.expand_path(redmine_root + "/config/environment") require 'spec' From 81db096316a4db26875463bb0f1d82577ca30fec Mon Sep 17 00:00:00 2001 From: jbbarth Date: Fri, 24 Aug 2012 18:23:49 +0200 Subject: [PATCH 04/15] Upgrade plugin to rspec 2.x with bundler --- .gitignore | 1 - Gemfile | 5 +++++ README.rdoc | 8 ++++++++ Rakefile | 42 ++++++++++++++++++++---------------------- spec/spec.opts | 5 +---- spec/spec_helper.rb | 5 ++--- 6 files changed, 36 insertions(+), 30 deletions(-) create mode 100644 Gemfile diff --git a/.gitignore b/.gitignore index 854c137..80f408e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ nbproject/ - diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..dceee4f --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +group :test do + gem 'rspec' + gem 'rspec-rails' + gem 'jeweler' +end diff --git a/README.rdoc b/README.rdoc index 0490216..61b6bf1 100644 --- a/README.rdoc +++ b/README.rdoc @@ -50,3 +50,11 @@ This plugin is licensed under the GNU GPL v2. See LICENSE.txt and GPL.txt for d If you need help you can contact the maintainer at the Bug Tracker. The bug tracker is located at: https://projects.littlestreamsoftware.com +== Running tests + +1. Go to your redmine root directory +2. Install the needed gems: bundle install +3. Prepare the database: RAILS_ENV=test rake db:create db:migrate redmine:plugins db:schema:dump db:fixtures:load +4. Run the tests with: rspec plugins/customer_plugin/spec + +NB: running the task directly from the plugin folder doesn't work really well with bundler, so it's not recommended. diff --git a/Rakefile b/Rakefile index 6d60344..4d6287b 100755 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,5 @@ #!/usr/bin/env ruby require "fileutils" -require 'rubygems' -gem 'rspec' -gem 'rspec-rails' Dir[File.expand_path(File.dirname(__FILE__)) + "/lib/tasks/**/*.rake"].sort.each { |ext| load ext } @@ -16,8 +13,8 @@ REDMINE_LIB = File.expand_path(REDMINE_ROOT + '/lib') require 'rake' require 'rake/clean' -require 'rake/rdoctask' -require 'spec/rake/spectask' +require 'rdoc/task' +require 'rspec/core/rake_task' PROJECT_NAME = 'customer_plugin' ZIP_FILE = PROJECT_NAME + ".zip" @@ -32,37 +29,38 @@ task :default => :spec task :stats => "spec:statsetup" desc "Run all specs in spec directory (excluding plugin specs)" -Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t| - t.spec_opts = ['--options', "\"#{PLUGIN_ROOT}/spec/spec.opts\""] - t.spec_files = FileList['spec/**/*_spec.rb'] +RSpec::Core::RakeTask.new(:spec => spec_prereq) do |t| + t.rspec_opts = ['--options', "\"#{PLUGIN_ROOT}/spec/spec.opts\""] + t.pattern = 'spec/**/*_spec.rb' end namespace :spec do desc "Run all specs in spec directory with RCov (excluding plugin specs)" - Spec::Rake::SpecTask.new(:rcov) do |t| - t.spec_opts = ['--options', "\"#{PLUGIN_ROOT}/spec/spec.opts\""] - t.spec_files = FileList['spec/**/*_spec.rb'] + RSpec::Core::RakeTask.new(:rcov) do |t| + t.rspec_opts = ['--options', "\"#{PLUGIN_ROOT}/spec/spec.opts\""] + t.pattern = 'spec/**/*_spec.rb' t.rcov = true + t.rcov_opts ||= [] t.rcov_opts << ["--rails", "--sort=coverage", "--exclude '/var/lib/gems,spec,#{REDMINE_APP},#{REDMINE_LIB}'"] end - desc "Print Specdoc for all specs (excluding plugin specs)" - Spec::Rake::SpecTask.new(:doc) do |t| - t.spec_opts = ["--format", "specdoc", "--dry-run"] - t.spec_files = FileList['spec/**/*_spec.rb'] + desc "Print RSpecdoc for all specs (excluding plugin specs)" + RSpec::Core::RakeTask.new(:doc) do |t| + t.rspec_opts = ["--format", "specdoc", "--dry-run"] + t.pattern = 'spec/**/*_spec.rb' end - desc "Print Specdoc for all specs as HTML (excluding plugin specs)" - Spec::Rake::SpecTask.new(:htmldoc) do |t| - t.spec_opts = ["--format", "html:doc/rspec_report.html", "--loadby", "mtime"] - t.spec_files = FileList['spec/**/*_spec.rb'] + desc "Print RSpecdoc for all specs as HTML (excluding plugin specs)" + RSpec::Core::RakeTask.new(:htmldoc) do |t| + t.rspec_opts = ["--format", "html:doc/rspec_report.html", "--loadby", "mtime"] + t.pattern = 'spec/**/*_spec.rb' end [:models, :controllers, :views, :helpers, :lib].each do |sub| desc "Run the specs under spec/#{sub}" - Spec::Rake::SpecTask.new(sub => spec_prereq) do |t| - t.spec_opts = ['--options', "\"#{PLUGIN_ROOT}/spec/spec.opts\""] - t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"] + RSpec::Core::RakeTask.new(sub => spec_prereq) do |t| + t.rspec_opts = ['--options', "\"#{PLUGIN_ROOT}/spec/spec.opts\""] + t.pattern = "spec/#{sub}/**/*_spec.rb" end end end diff --git a/spec/spec.opts b/spec/spec.opts index 2144705..e31944b 100644 --- a/spec/spec.opts +++ b/spec/spec.opts @@ -1,7 +1,4 @@ --colour --format progress ---loadby -mtime ---reverse ---backtrace \ No newline at end of file +--backtrace diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index df94151..507d7fd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,10 +6,9 @@ redmine_root = ENV["REDMINE_ROOT"] || File.dirname(__FILE__) + "/../../.." require File.expand_path(redmine_root + "/config/environment") -require 'spec' -require 'spec/rails' +require 'rspec/rails' -Spec::Runner.configure do |config| +RSpec.configure do |config| # If you're not using ActiveRecord you should remove these # lines, delete config/database.yml and disable :active_record # in your config/boot.rb From 14190a5cbbb433548a98a817c998172244f95698 Mon Sep 17 00:00:00 2001 From: jbbarth Date: Fri, 24 Aug 2012 18:27:06 +0200 Subject: [PATCH 05/15] Updated specs for ActiveModel new syntax about errors See: http://stackoverflow.com/questions/7526499/undefined-method-on-for-actionmodel --- spec/models/customer_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb index 7b7a624..e1b5b18 100644 --- a/spec/models/customer_spec.rb +++ b/spec/models/customer_spec.rb @@ -11,12 +11,12 @@ it 'should require a name if company is not set' do @customer.should_not be_valid - @customer.errors.on(:name).should_not be_empty + @customer.errors.get(:name).should_not be_empty end it 'should require a company if name is not set' do @customer.should_not be_valid - @customer.errors.on(:company).should_not be_empty + @customer.errors.get(:company).should_not be_empty end it 'should be valid if name is set but company is missing' do @@ -36,7 +36,7 @@ @conflict_customer = Customer.new( :name => 'John Customer', :company => "ABC Company") @conflict_customer.should_not be_valid - @conflict_customer.errors.on(:name).should_not be_empty + @conflict_customer.errors.get(:name).should_not be_empty end describe 'with an invalid email' do From 817e50affdc42baba2ac24fd8f3691626fe1c0d9 Mon Sep 17 00:00:00 2001 From: jbbarth Date: Fri, 24 Aug 2012 18:29:25 +0200 Subject: [PATCH 06/15] Added constraint about Redmine version because we're about to make non 1.x compatible changes --- rails/init.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/rails/init.rb b/rails/init.rb index ae2abd1..03edafd 100644 --- a/rails/init.rb +++ b/rails/init.rb @@ -12,6 +12,7 @@ url 'https://projects.littlestreamsoftware.com/projects/redmine-customers' if respond_to? :url author_url 'http://www.littlestreamsoftware.com' if respond_to? :author_url + requires_redmine :version_or_higher => '2.0.0' project_module :customer_module do permission :view_customer, {:customers => [:show]} From 5aed317c5b4ab7e2b742ea49a00260bebbc76538 Mon Sep 17 00:00:00 2001 From: jbbarth Date: Fri, 24 Aug 2012 18:57:11 +0200 Subject: [PATCH 07/15] Added some routes since the catch-all route doesn't exist in the core anymore --- config/routes.rb | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 config/routes.rb diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..830e0ca --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,3 @@ +RedmineApp::Application.routes.draw do + get '/projects/:id/customers/:action', :controller => 'customers' +end From 27c9de87c7216f1d2409cf7549d7ec84e5ec5042 Mon Sep 17 00:00:00 2001 From: jbbarth Date: Fri, 24 Aug 2012 19:30:41 +0200 Subject: [PATCH 08/15] Updated customers/list icon --- app/views/customers/edit.html.erb | 4 ++-- app/views/customers/list.html.erb | 2 +- app/views/customers/new.html.erb | 4 ++-- app/views/customers/select.html.erb | 2 +- app/views/customers/show.html.erb | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/views/customers/edit.html.erb b/app/views/customers/edit.html.erb index 2f72a3d..91a4956 100644 --- a/app/views/customers/edit.html.erb +++ b/app/views/customers/edit.html.erb @@ -14,6 +14,6 @@ <% content_for(:header_tags) do %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/customers/list.html.erb b/app/views/customers/list.html.erb index 6d52ee3..48dbf95 100644 --- a/app/views/customers/list.html.erb +++ b/app/views/customers/list.html.erb @@ -27,7 +27,7 @@ <% content_for(:header_tags) do %> <% end %> diff --git a/app/views/customers/new.html.erb b/app/views/customers/new.html.erb index bedcca0..b26386e 100644 --- a/app/views/customers/new.html.erb +++ b/app/views/customers/new.html.erb @@ -14,6 +14,6 @@ <% content_for(:header_tags) do %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/customers/select.html.erb b/app/views/customers/select.html.erb index 5b9ed4f..1527056 100644 --- a/app/views/customers/select.html.erb +++ b/app/views/customers/select.html.erb @@ -22,6 +22,6 @@ <% content_for(:header_tags) do %> <% end %> diff --git a/app/views/customers/show.html.erb b/app/views/customers/show.html.erb index d2f2edf..e5cc184 100644 --- a/app/views/customers/show.html.erb +++ b/app/views/customers/show.html.erb @@ -24,6 +24,6 @@ <% content_for(:header_tags) do %> -<% end %> \ No newline at end of file +<% end %> From ca577083a0470278493dfbadfe6a8b9c7593dea1 Mon Sep 17 00:00:00 2001 From: jbbarth Date: Fri, 24 Aug 2012 21:47:54 +0200 Subject: [PATCH 09/15] Fixed fixtures path in spec_helper --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 507d7fd..b6fb92c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,7 +14,7 @@ # in your config/boot.rb config.use_transactional_fixtures = true config.use_instantiated_fixtures = false - config.fixture_path = Rails.root + '/spec/fixtures/' + config.fixture_path = redmine_root + '/test/fixtures/' # == Fixtures # From 1ed9682e10eecdef3c99d443fb435af8b6146077 Mon Sep 17 00:00:00 2001 From: jbbarth Date: Fri, 24 Aug 2012 22:06:18 +0200 Subject: [PATCH 10/15] Fixed wrong number of arguments in customers/new partial --- app/views/customers/new.html.erb | 2 +- spec/controllers/customers_controller_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/views/customers/new.html.erb b/app/views/customers/new.html.erb index b26386e..7e22654 100644 --- a/app/views/customers/new.html.erb +++ b/app/views/customers/new.html.erb @@ -7,7 +7,7 @@

<%= l(:label_customer_new) %>

-<% labelled_tabular_form_for :customer, @customer, :url =>{:action => 'create', :id => @project} do |f| %> +<%= labelled_tabular_form_for @customer, :url =>{:action => 'create', :id => @project} do |f| %> <%= render :partial => 'form', :locals => {:f => f} %> <%= submit_tag l(:button_save) -%> <% end -%> diff --git a/spec/controllers/customers_controller_spec.rb b/spec/controllers/customers_controller_spec.rb index de50117..1a54f47 100644 --- a/spec/controllers/customers_controller_spec.rb +++ b/spec/controllers/customers_controller_spec.rb @@ -1,2 +1,18 @@ require File.dirname(__FILE__) + '/../spec_helper' +describe CustomersController do + fixtures :projects + render_views #slow, but we don't have view tests + + before do + request.session[:user_id] = 1 # login as admin + Project.find(1).enable_module!(:customer_module) + end + + describe "GET new" do + it "renders the form successfully" do + get :new, :id => Project.find(1) + response.should be_success + end + end +end From d7210f49d95994f9033da5cc9571b62a1428bec8 Mon Sep 17 00:00:00 2001 From: jbbarth Date: Fri, 24 Aug 2012 22:08:16 +0200 Subject: [PATCH 11/15] Less restrictive routes so that create/update/destroy actions work --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 830e0ca..54d768a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,3 @@ RedmineApp::Application.routes.draw do - get '/projects/:id/customers/:action', :controller => 'customers' + match '/projects/:id/customers/:action', :controller => 'customers' end From 9fafde9e420df71b135a6a3a8cb1aa6536f9b643 Mon Sep 17 00:00:00 2001 From: jbbarth Date: Fri, 24 Aug 2012 22:24:57 +0200 Subject: [PATCH 12/15] Display form correctly in customers/select partial --- app/views/customers/select.html.erb | 2 +- spec/controllers/customers_controller_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/views/customers/select.html.erb b/app/views/customers/select.html.erb index 1527056..0dd4658 100644 --- a/app/views/customers/select.html.erb +++ b/app/views/customers/select.html.erb @@ -7,7 +7,7 @@

<%= l(:label_customer_assign) %>

-<% form_for :customer, :url =>{:action => 'assign', :id => @project} do |f| %> +<%= form_for :customer, :url =>{:action => 'assign', :id => @project} do |f| %>

diff --git a/spec/controllers/customers_controller_spec.rb b/spec/controllers/customers_controller_spec.rb index 1a54f47..aac2166 100644 --- a/spec/controllers/customers_controller_spec.rb +++ b/spec/controllers/customers_controller_spec.rb @@ -15,4 +15,12 @@ response.should be_success end end + + describe "GET select" do + it "renders the form successfully" do + get :select, :id => Project.find(1) + response.should be_success + response.body.should =~ /