Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed redmine-2.1 compatibility

  • Loading branch information...
commit 9d999f9ff3e7511f49abb5c0ca69755085fbc3a2 1 parent c5672f0
@nettsundere nettsundere authored
View
9 Gemfile
@@ -1,7 +1,2 @@
-gem "acts-as-taggable-on",
- :git => "git://github.com/Undev/acts-as-taggable-on.git",
- :branch => "rails2"
-
-gem "rails_sql_views",
- :git => "git://github.com/Undev/rails_sql_views.git",
- :branch => "rails2"
+gem 'acts-as-taggable-on', '~> 2.3.1'
+gem "rails_sql_views", :git => "git://github.com/anathematic/rails_sql_views.git"
View
4 README.rdoc
@@ -27,7 +27,7 @@ You need to set up database for acts-as-taggable-on:
1a) for Rails 2 (which Redmine currently uses):
$ env RAILS_ENV=production script/generate acts_as_taggable_on_migration
1b) for Rails 3:
- $ rails generation acts_as_taggable_on:migration
+ $ rails generate acts_as_taggable_on:migration
2)
$ rake db:migrate RAILS_ENV=production
$ rake db:migrate_plugins RAILS_ENV=production
@@ -67,4 +67,4 @@ into
add_index :taggings, :taggable_type
add_index :taggings, :context
-in the migration of acts-as-taggable-on
+in the migration of acts-as-taggable-on
View
12 Rakefile
@@ -1,12 +0,0 @@
-require 'rake'
-require 'rake/testtask'
-
-desc "Default: run unit tests."
-task :default => :test
-
-desc "Test the redmine_tagging plugin."
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = true
-end
View
2  app/controllers/issue_tags_controller.rb
@@ -10,7 +10,7 @@ def destroy
context = TaggingPlugin::ContextHelper.context_for(@project)
- tag.taggings.find_each(:conditions => ['context=?', context]) do |tagging|
+ tag.taggings.where(:context => context).find_each do |tagging|
if tagging.taggable_type = "Issue"
affected_issue = Issue.find(tagging.taggable_id)
affected_issue.init_journal(User.current)
View
2  app/helpers/application_helper.rb → app/helpers/tagging_helper.rb
@@ -1,4 +1,4 @@
-module ApplicationHelper
+module TaggingHelper
def link_to_project_tag_filter(project, tag, options = {}, html_options = {})
options.reverse_merge!({
:status => 'o',
View
2  app/models/issue_tag.rb
@@ -1,4 +1,6 @@
class IssueTag < ActiveRecord::Base
+ set_primary_key :id
+
belongs_to :issue
def readonly?
View
2  app/models/wiki_page_tag.rb
@@ -1,4 +1,6 @@
class WikiPageTag < ActiveRecord::Base
+ set_primary_key :id
+
belongs_to :wiki_page
def readonly?
View
16 app/views/issues/index.api.rsb → app/views/issues/index_with_tags.api.rsb
@@ -11,12 +11,12 @@ api.array :issues, api_meta(:total_count => @issue_count, :offset => @offset, :l
api.category(:id => issue.category_id, :name => issue.category.name) unless issue.category.nil?
api.fixed_version(:id => issue.fixed_version_id, :name => issue.fixed_version.name) unless issue.fixed_version.nil?
api.parent(:id => issue.parent_id) unless issue.parent.nil?
-
- api.subject issue.subject
+
+ api.subject issue.subject
api.description issue.description
- api.start_date issue.start_date
- api.due_date issue.due_date
- api.done_ratio issue.done_ratio
+ api.start_date issue.start_date
+ api.due_date issue.due_date
+ api.done_ratio issue.done_ratio
api.estimated_hours issue.estimated_hours
render_api_custom_values issue.custom_field_values, api
@@ -29,6 +29,12 @@ api.array :issues, api_meta(:total_count => @issue_count, :offset => @offset, :l
api.tag(:id => issue_tag.tag[1..-1])
end
end
+
+ api.array :relations do
+ issue.relations.each do |relation|
+ api.relation(:id => relation.id, :issue_id => relation.issue_from_id, :issue_to_id => relation.issue_to_id, :relation_type => relation.relation_type, :delay => relation.delay)
+ end
+ end if include_in_api_response?('relations')
end
end
end
View
73 app/views/issues/show_with_tags.api.rsb
@@ -0,0 +1,73 @@
+api.issue do
+ api.id @issue.id
+ api.project(:id => @issue.project_id, :name => @issue.project.name) unless @issue.project.nil?
+ api.tracker(:id => @issue.tracker_id, :name => @issue.tracker.name) unless @issue.tracker.nil?
+ api.status(:id => @issue.status_id, :name => @issue.status.name) unless @issue.status.nil?
+ api.priority(:id => @issue.priority_id, :name => @issue.priority.name) unless @issue.priority.nil?
+ api.author(:id => @issue.author_id, :name => @issue.author.name) unless @issue.author.nil?
+ api.assigned_to(:id => @issue.assigned_to_id, :name => @issue.assigned_to.name) unless @issue.assigned_to.nil?
+ api.category(:id => @issue.category_id, :name => @issue.category.name) unless @issue.category.nil?
+ api.fixed_version(:id => @issue.fixed_version_id, :name => @issue.fixed_version.name) unless @issue.fixed_version.nil?
+ api.parent(:id => @issue.parent_id) unless @issue.parent.nil?
+
+ api.subject @issue.subject
+ api.description @issue.description
+ api.start_date @issue.start_date
+ api.due_date @issue.due_date
+ api.done_ratio @issue.done_ratio
+ api.estimated_hours @issue.estimated_hours
+ api.spent_hours(@issue.spent_hours) if User.current.allowed_to?(:view_time_entries, @project)
+
+ render_api_custom_values @issue.custom_field_values, api
+
+ api.created_on @issue.created_on
+ api.updated_on @issue.updated_on
+
+ api.array :tags do
+ @issue.issue_tags.each do |issue_tag|
+ api.tag(:id => issue_tag.tag[1..-1])
+ end
+ end
+
+ render_api_issue_children(@issue, api) if include_in_api_response?('children')
+
+ api.array :attachments do
+ @issue.attachments.each do |attachment|
+ render_api_attachment(attachment, api)
+ end
+ end if include_in_api_response?('attachments')
+
+ api.array :relations do
+ @relations.each do |relation|
+ api.relation(:id => relation.id, :issue_id => relation.issue_from_id, :issue_to_id => relation.issue_to_id, :relation_type => relation.relation_type, :delay => relation.delay)
+ end
+ end if include_in_api_response?('relations') && @relations.present?
+
+ api.array :changesets do
+ @issue.changesets.each do |changeset|
+ api.changeset :revision => changeset.revision do
+ api.user(:id => changeset.user_id, :name => changeset.user.name) unless changeset.user.nil?
+ api.comments changeset.comments
+ api.committed_on changeset.committed_on
+ end
+ end
+ end if include_in_api_response?('changesets') && User.current.allowed_to?(:view_changesets, @project)
+
+ api.array :journals do
+ @issue.journals.each do |journal|
+ api.journal :id => journal.id do
+ api.user(:id => journal.user_id, :name => journal.user.name) unless journal.user.nil?
+ api.notes journal.notes
+ api.created_on journal.created_on
+ api.array :details do
+ journal.details.each do |detail|
+ api.detail :property => detail.property, :name => detail.prop_key do
+ api.old_value detail.old_value
+ api.new_value detail.value
+ end
+ end
+ end
+ end
+ end
+ end if include_in_api_response?('journals')
+end
View
3  assets/javascripts/jquery_loader.js
@@ -1,3 +0,0 @@
-if(typeof jQuery == 'undefined') {
- document.write('<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>')
-}
View
4 config/routes.rb
@@ -1,3 +1,3 @@
-ActionController::Routing::Routes.draw do |map|
- map.resources :issue_tags, :only => [:destroy]
+RedmineApp::Application.routes.draw do
+ resources :issue_tags, :only => [:destroy]
end
View
19 init.rb
@@ -1,9 +1,9 @@
require 'redmine'
-require 'dispatcher'
-Dispatcher.to_prepare do
- require_dependency 'tagging_plugin/tagging_patches'
- require_dependency 'tagging_plugin/tagging_query_patch'
+ActionDispatch::Callbacks.to_prepare do
+ require 'tagging_plugin/tagging_patches'
+ require 'tagging_plugin/tagging_query_patch'
+ require 'tagging_plugin/api_template_handler_patch'
if !Issue.searchable_options[:include].include? :issue_tags
Issue.searchable_options[:columns] << "#{IssueTag.table_name}.tag"
@@ -11,15 +11,6 @@
end
if !WikiPage.searchable_options[:include].include? :wiki_page_tags
- # I now know _way_ to much about activerecord... activerecord
- # builds an SQL string, _then scans that string_ for tables to use
- # in its join constructions. I really do hope that's a temporary
- # workaround. Why it has ever worked is beyond me. Reference:
- # construct_finder_sql_for_association_limiting in
- # active_record/associations.rb
- WikiPage.searchable_options[:columns] = WikiPage.searchable_options[:columns].select{|c| c != 'text'}
- WikiPage.searchable_options[:columns] << "#{WikiContent.table_name}.text"
-
WikiPage.searchable_options[:columns] << "#{WikiPageTag.table_name}.tag"
WikiPage.searchable_options[:include] << :wiki_page_tags
end
@@ -100,7 +91,7 @@
link_to(tag, search_url)
end.join('&nbsp;')
- "<div class='tags'>#{taglinks}</div>"
+ raw("<div class='tags'>#{taglinks}</div>")
else
''
end
View
34 lib/tagging_plugin/api_template_handler_patch.rb
@@ -0,0 +1,34 @@
+module TaggingPlugin
+ module ApiTemplateHandlerPatch
+ class << self
+ def included(base)
+ base.send(:extend, ClassMethods)
+ base.class_eval do
+ class << self
+ alias_method_chain :call, :api_replacement
+ end
+ end
+ end
+ end
+
+ module ClassMethods
+ def call_with_api_replacement(template)
+ template = replace_if(template, /views\/issues\/index.api.rsb$/, "plugins/redmine_tagging/app/views/issues/index_with_tags.api.rsb")
+ template = replace_if(template, /views\/issues\/show.api.rsb$/, "plugins/redmine_tagging/app/views/issues/show_with_tags.api.rsb")
+ call_without_api_replacement(template)
+ end
+
+ def replace_if(template, regexp, new_path)
+ if template.identifier =~ regexp
+ source = File.open(new_path).read
+ identifier = template.identifier
+ handler = template.handler
+ template = ActionView::Template.new(source, identifier, handler, {})
+ end
+ template
+ end
+ end
+ end
+end
+
+Redmine::Views::ApiTemplateHandler.send(:include, TaggingPlugin::ApiTemplateHandlerPatch)
View
18 lib/tagging_plugin/tagging_hooks.rb
@@ -30,11 +30,9 @@ def view_layouts_base_html_head(context = {})
})
result = <<-TAGS
- #{javascript_include_tag 'jquery_loader', :plugin => 'redmine_tagging'}
<script type="text/javascript">
- var $j = jQuery.noConflict()
- $j(function() {
- $j('#sidebar').append("#{escape_javascript(tag_cloud)}")
+ $(function() {
+ $('#sidebar').append("#{escape_javascript(tag_cloud)}")
})
</script>
TAGS
@@ -93,9 +91,8 @@ def view_issues_form_details_bottom(context={ })
ac = ac.collect{|tag| "'#{escape_javascript(tag.gsub(/^#/, ''))}'"}.join(', ')
tags += <<-generatedscript
<script type="text/javascript">
- var $j = jQuery.noConflict()
- $j(document).ready(function() {
- $j('#issue_tags').tagSuggest({ tags: [#{ac}] })
+ $(document).ready(function() {
+ $('#issue_tags').tagSuggest({ tags: [#{ac}] })
})
</script>
generatedscript
@@ -188,10 +185,9 @@ def view_layouts_base_content(context = {})
tags += <<-generatedscript
<script type="text/javascript">
- var $j = jQuery.noConflict()
- $j(document).ready(function() {
- $j('#tagging_wiki_edit_block').insertAfter($j("#content_text"))
- $j('#wiki_page_tags').tagSuggest({ tags: [#{ac}] })
+ $(document).ready(function() {
+ $('#tagging_wiki_edit_block').insertAfter($("#content_text"))
+ $('#wiki_page_tags').tagSuggest({ tags: [#{ac}] })
})
</script>
generatedscript
View
23 lib/tagging_plugin/tagging_patches.rb
@@ -61,6 +61,7 @@ def self.included(base) # :nodoc:
before_save :update_tags
acts_as_taggable
+
after_save :cleanup_tags
has_many :issue_tags
@@ -98,6 +99,8 @@ def update_tags
# Fix context if project changed
if project_id_changed? && !new_record?
+ @new_project_id = project_id
+
taggings.update_all(:context => project_context)
end
@@ -109,17 +112,25 @@ def update_tags
end
def cleanup_tags
- if project_id_changed?
+ if @new_project_id
context = ContextHelper.context_for(project)
- condition = ["context != ? AND taggable_id = ? AND taggable_type= ?", context, id, "Issue"]
- ActsAsTaggableOn::Tagging.delete_all(condition)
+ ActsAsTaggableOn::Tagging.where("
+ context!=? AND taggable_id=? AND taggable_type=?",
+ context, id, "Issue").delete_all
end
-
true
end
end
end
+ module TaggingHelperPatch
+ def self.included(base)
+ base.class_eval do
+ helper :tagging
+ end
+ end
+ end
+
module WikiControllerPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
@@ -147,6 +158,10 @@ def update_with_tags
WikiPage.send(:include, TaggingPlugin::WikiPagePatch) unless WikiPage.included_modules.include? TaggingPlugin::WikiPagePatch
+[IssuesController, ReportsController, WikiController, ProjectsController].each do |controller|
+ controller.send(:include, TaggingPlugin::TaggingHelperPatch) unless controller.include? TaggingPlugin::TaggingHelperPatch
+end
+
WikiController.send(:include, TaggingPlugin::WikiControllerPatch) unless WikiController.included_modules.include? TaggingPlugin::WikiControllerPatch
ProjectsHelper.send(:include, TaggingPlugin::ProjectsHelperPatch) unless ProjectsHelper.included_modules.include? TaggingPlugin::ProjectsHelperPatch
View
4 lib/tagging_plugin/tagging_query_patch.rb
@@ -11,7 +11,8 @@ def self.included(base) # :nodoc:
alias_method_chain :available_filters, :tags
alias_method_chain :sql_for_field, :tags
- add_available_column(QueryColumn.new(:issue_tags, :caption => :tags))
+ tag_query_column = QueryColumn.new(:issue_tags, :caption => :field_tags)
+ add_available_column(tag_query_column)
end
end
@@ -34,6 +35,7 @@ def available_filters_with_tags
"tags" => {
:type => :list_optional,
:values => tags,
+ :name => l(:field_tags),
:order => 20
}
}
View
8 test/functional/issue_tags_controller_test.rb
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class IssueTagsControllerTest < ActionController::TestCase
- fixtures :all
+ fixtures :projects, :issues, :users, :trackers, :issue_statuses
def setup
@request.session[:user_id] = 2
@@ -9,7 +9,7 @@ def setup
@issue_with_tags = setup_issue_with_tags(@some_tags)
@project_with_tags = @issue_with_tags.project
- @another_project = Project.find(:first, :conditions => ["id != ?", @project_with_tags.id])
+ @another_project = Project.generate!
end
def test_should_destroy_issue_tag
@@ -24,7 +24,9 @@ def test_should_destroy_issue_tag
def test_should_destroy_issue_tag_in_case_of_changed_project
@issue_with_tags.project = @another_project
- @issue_with_tags.tracker = @another_project.trackers.first
+
+ some_tracker = @issue_with_tags.project.trackers.create!(:name => "test")
+ @issue_with_tags.tracker = some_tracker
@issue_with_tags.save!
@issue_with_tags.reload
View
39 test/functional/issues_controller_test.rb
@@ -1,21 +1,50 @@
require File.dirname(__FILE__) + '/../test_helper'
class IssuesControllerTest < ActionController::TestCase
- fixtures :all
+ fixtures :projects, :issues, :users, :trackers
def setup
@request.session[:user_id] = 2
+ User.stubs(:current).returns(User.find_by_id(2))
+ User.any_instance.stubs(:allowed_to?).returns(true)
+ Mailer.stubs(:deliver_mail).returns(true)
@some_tags = "#1, #2, #3,#4,#5"
@issue_with_tags = setup_issue_with_tags(@some_tags)
+ @issue_without_tags = setup_issue_with_tags("")
+
+ @issues_to_bulk_edit = [@issue_with_tags, @issue_without_tags]
+
@project_with_tags = @issue_with_tags.project
+ @another_project = Project.generate!
+
+ Issue.stubs(:allowed_target_projects_on_move).returns(Project.all)
+ end
+
+ def test_can_index_api
+ get :index, :format => 'json'
+ assert_response :success
+ end
- @another_project = Project.find(:first, :conditions => ["id != ?", @project_with_tags.id])
+ def test_can_show_api
+ get :show, :id => @issue_with_tags.id, :format => 'xml'
+ assert_response :success
+ end
+
+ def test_index_api_rsb_should_not_raise_in_project_issues
+ get :index, :project_id => @project_with_tags.id
+ end
+
+ def test_can_show_api_for_some_project
+ get :index, :format => 'json', :project_id => @project_with_tags.id
+ assert_response :success
end
def test_bulk_update_with_project_change_should_success
tag_input = '"1 2 \\\\ 3 cool/tag 777 '
- put :bulk_update, { :ids => Issue.all.map(&:id), :issue => { :tags => tag_input, :project_id => @another_project.id }, 'append_tags' => "on" }
+
+ put :bulk_update, { :ids => @issues_to_bulk_edit.map(&:id), :issue => { :project_id => @another_project.id, :tags => tag_input }, :append_tags =>"on" }
+
assert_response :redirect
@issue_with_tags.reload
@@ -27,7 +56,7 @@ def test_bulk_update_with_project_change_should_success
def test_bulk_update_without_project_change_should_success
tag_input = '"1 2 \\\\ 3 cool/tag 777 '
- put :bulk_update, { :ids => Issue.all.map(&:id), :issue => { :tags => tag_input }, 'append_tags' => "on" }
+ put :bulk_update, { :ids => @issues_to_bulk_edit.map(&:id), :issue => { :tags => tag_input }, 'append_tags' => "on" }
assert_response :redirect
@issue_with_tags.reload
@@ -38,7 +67,7 @@ def test_bulk_update_without_project_change_should_success
end
def test_bulk_update_without_tags_field_should_not_drop_tags
- put :bulk_update, { :ids => Issue.all.map(&:id), :issue => { :status_id => 1 }}
+ put :bulk_update, { :ids => @issues_to_bulk_edit.map(&:id), :issue => { :status_id => 1 }}
assert_response :redirect
@issue_with_tags.reload
View
27 test/integration/tagging_test.rb
@@ -1,10 +1,13 @@
require File.dirname(__FILE__) + '/../test_helper'
class TaggingTest < ActionController::IntegrationTest
- fixtures :all
+ fixtures :projects, :issues, :users, :trackers, :issue_statuses
def setup
+ Mailer.stubs(:deliver_mail).returns(true)
+
log_user("admin", "admin")
+ User.any_instance.stubs(:allowed_to?).returns(true)
@some_tags = "#1, #2, #3,#4,#5"
@issue_with_tags = setup_issue_with_tags(@some_tags)
@@ -12,7 +15,7 @@ def setup
@wiki_page_with_tags_content = @wiki_page_with_tags.content
@project_with_tags = @issue_with_tags.project
- @another_project = Project.find(:first, :conditions => ["id != ?", @project_with_tags.id])
+ @another_project = Project.generate!
@project_with_wiki_tags = @wiki_page_with_tags.project
@another_project_context = TaggingPlugin::ContextHelper.context_for(@another_project)
@@ -25,10 +28,12 @@ def setup
def test_should_create_issue_tags_from_input
Setting.plugin_redmine_tagging[:issues_inline] = "0"
- @new_issue_attrs = @issue_with_tags.attributes.merge({
+ @new_issue_attrs = {
+ "project_id" => @project_with_tags.id,
+ "priority_id" => @issue_with_tags.priority_id,
"subject" => "new_issue",
"tags" => "10 11 12"
- })
+ }
get_via_redirect(new_project_issue_path(@project_with_tags))
assert_response :success
@@ -44,7 +49,7 @@ def test_should_update_issue_tags_from_input
Setting.plugin_redmine_tagging[:issues_inline] = "0"
issue_attrs = @issue_with_tags.attributes
-
+
issue_attrs['project_id'] = @another_project.id
issue_attrs['tracker'] = @another_project.trackers.first
issue_attrs['tags'] = "10 11 12"
@@ -64,10 +69,12 @@ def test_should_update_issue_tags_from_input
def test_should_create_inline_issue_tags
Setting.plugin_redmine_tagging[:issues_inline] = "1"
- @new_issue_attrs = @issue_with_tags.attributes.merge({
+ @new_issue_attrs = {
+ "project_id" => @project_with_tags.id,
+ "priority_id" => @issue_with_tags.priority_id,
"subject" => "new_issue",
"description" => "{{tag(10 11 12)}}"
- })
+ }
get_via_redirect(new_project_issue_path(@project_with_tags))
assert_response :success
@@ -96,7 +103,7 @@ def test_should_update_inline_issue_tags
assert_response :success
@issue_with_tags.reload
- assert_equal 2, @issue_with_tags.taggings.size
+ assert_equal 2, @issue_with_tags.taggings.count
assert_equal [@another_project_context], @issue_with_tags.taggings.map(&:context).uniq
end
end
@@ -119,7 +126,7 @@ def test_should_create_wiki_page_tags_from_input
get_via_redirect(page_path)
assert_response :success
- new_page = WikiPage.find_by_title("newpage")
+ new_page = WikiPage.find_by_title("Newpage")
assert_equal 3, new_page.taggings.size
assert_equal [@project_with_wiki_tags_context], new_page.taggings.map(&:context).uniq
end
@@ -164,7 +171,7 @@ def test_should_create_inline_wiki_page_tags
get_via_redirect(page_path)
assert_response :success
- new_page = WikiPage.find_by_title("newpage")
+ new_page = WikiPage.find_by_title("Newpage")
assert_equal 2, new_page.taggings.size
assert_equal [@project_with_wiki_tags_context], new_page.taggings.map(&:context).uniq
end
View
25 test/test_helper.rb
@@ -1,13 +1,26 @@
# Load the normal Rails helper
-require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper')
+require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper')
+
+require 'test/unit/util/backtracefilter'
+
+module Test::Unit::Util::BacktraceFilter
+ def filter_backtrace(backtrace, prefix=nil)
+ backtrace
+ end
+end
def setup_issue_with_tags(test_tags)
- public_project = Project.first(["is_public=?", true])
- some_issue = public_project.issues.first
+ public_project = Project.generate!(:is_public => true)
+ tracker = Tracker.generate!
+ priority = IssuePriority.new(:name => "test_priority#{public_project.id}")
+ priority.save!
+ public_project.trackers << tracker
+
+ issue = Issue.generate!(:project_id => public_project.id, :tracker => tracker, :priority => priority)
- some_issue.tags_to_update = test_tags
- some_issue.save!
- some_issue
+ issue.tags_to_update = test_tags
+ issue.save!
+ issue
end
def setup_wiki_page_with_tags(test_tags)
Please sign in to comment.
Something went wrong with that request. Please try again.