Feature #1448 » 0001-Adds-tags-to-issues.patch
| Gemfile | ||
|---|---|---|
|
gem "i18n", "~> 1.6.0"
|
||
|
gem "rbpdf", "~> 1.20.0"
|
||
|
# Tags
|
||
|
gem 'acts-as-taggable-on', '~> 6.0'
|
||
|
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
||
|
gem 'tzinfo-data', platforms: [:mingw, :x64_mingw, :mswin]
|
||
| app/models/issue.rb | ||
|---|---|---|
|
acts_as_activity_provider :scope => preload(:project, :author, :tracker, :status),
|
||
|
:author_key => :author_id
|
||
|
acts_as_ordered_taggable
|
||
|
DONE_RATIO_OPTIONS = %w(issue_field issue_status)
|
||
| ... | ... | |
|
@total_estimated_hours = nil
|
||
|
@last_updated_by = nil
|
||
|
@last_notes = nil
|
||
|
@tags = nil
|
||
|
base_reload(*args)
|
||
|
end
|
||
| ... | ... | |
|
'estimated_hours',
|
||
|
'custom_field_values',
|
||
|
'custom_fields',
|
||
|
'tag_list',
|
||
|
'lock_version',
|
||
|
'notes',
|
||
|
:if => lambda {|issue, user| issue.new_record? || issue.attributes_editable?(user) }
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
def tags
|
||
|
if @tags
|
||
|
@tags
|
||
|
else
|
||
|
tag_list
|
||
|
end
|
||
|
end
|
||
|
# Preloads relations for a collection of issues
|
||
|
def self.load_relations(issues)
|
||
|
if issues.any?
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
# Preloads tags for a collection of issues
|
||
|
def self.load_issues_tags(issues)
|
||
|
if issues.any?
|
||
|
tags = ActsAsTaggableOn::Tag.joins(:taggings)
|
||
|
.select("#{ActsAsTaggableOn::Tag.table_name}.id", "#{ActsAsTaggableOn::Tag.table_name}.name",
|
||
|
"#{ActsAsTaggableOn::Tagging.table_name}.taggable_id")
|
||
|
.where(:taggings => {:taggable_type => 'Issue', :taggable_id => issues.map(&:id), :context => 'tags'})
|
||
|
.order("#{ActsAsTaggableOn::Tagging.table_name}.id")
|
||
|
issues.each do |issue|
|
||
|
issue.instance_variable_set "@tags", (tags.select{|t| t.taggable_id == issue.id} || [])
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
# Returns a scope of the given issues and their descendants
|
||
|
def self.self_and_descendants(issues)
|
||
|
Issue.joins("JOIN #{Issue.table_name} ancestors" +
|
||
| app/models/issue_query.rb | ||
|---|---|---|
|
TimestampQueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on", :default_order => 'desc', :groupable => true),
|
||
|
TimestampQueryColumn.new(:closed_on, :sortable => "#{Issue.table_name}.closed_on", :default_order => 'desc', :groupable => true),
|
||
|
QueryColumn.new(:last_updated_by, :sortable => lambda {User.fields_for_order_statement("last_journal_user")}),
|
||
|
QueryColumn.new(:tags, :caption => :field_tags),
|
||
|
QueryColumn.new(:relations, :caption => :label_related_issues),
|
||
|
QueryColumn.new(:attachments, :caption => :label_attachment_plural),
|
||
|
QueryColumn.new(:description, :inline => false),
|
||
| ... | ... | |
|
:values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]]
|
||
|
end
|
||
|
add_available_filter('tags', :type => :list_optional, :name => l(:field_tags),
|
||
|
:values => lambda { tags_values })
|
||
|
add_available_filter "attachment",
|
||
|
:type => :text, :name => l(:label_attachment)
|
||
| ... | ... | |
|
if has_column?(:last_notes)
|
||
|
Issue.load_visible_last_notes(issues)
|
||
|
end
|
||
|
if has_column?(:tags)
|
||
|
Issue.load_issues_tags(issues)
|
||
|
end
|
||
|
issues
|
||
|
rescue ::ActiveRecord::StatementInvalid => e
|
||
|
raise StatementInvalid.new(e.message)
|
||
| ... | ... | |
|
sql_for_field(field, operator, value, Project.table_name, "status")
|
||
|
end
|
||
|
def sql_for_tags_field(field, operator, value)
|
||
|
case operator
|
||
|
when '=', '!'
|
||
|
issues = Issue.tagged_with(values_for('tags'), any: true)
|
||
|
when '!*'
|
||
|
issues = Issue.tagged_with ActsAsTaggableOn::Tag.all.map(&:to_s), exclude: true
|
||
|
else
|
||
|
issues = Issue.tagged_with ActsAsTaggableOn::Tag.all.map(&:to_s), any: true
|
||
|
end
|
||
|
compare = operator.eql?('!') ? 'NOT IN' : 'IN'
|
||
|
issue_ids = issues.collect {|issue| issue.id }.push(0).join(',')
|
||
|
"( #{ Issue.table_name }.id #{ compare } (#{ issue_ids }) )"
|
||
|
end
|
||
|
def find_assigned_to_id_filter_values(values)
|
||
|
Principal.visible.where(:id => values).map {|p| [p.name, p.id.to_s]}
|
||
|
end
|
||
| app/models/journal.rb | ||
|---|---|---|
|
h[c.custom_field_id] = c.value
|
||
|
h
|
||
|
end
|
||
|
@tags_before_change = journalized.tags
|
||
|
end
|
||
|
self
|
||
|
end
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
end
|
||
|
if @tags_before_change
|
||
|
new_tags = journalized.send('tags')
|
||
|
if new_tags != @tags_before_change
|
||
|
add_attribute_detail('tags', @tags_before_change.to_s, new_tags.to_s)
|
||
|
end
|
||
|
end
|
||
|
start
|
||
|
end
|
||
| app/models/query.rb | ||
|---|---|---|
|
]
|
||
|
end
|
||
|
def tags_values
|
||
|
issues_scope = Issue.visible.select("#{Issue.table_name}.id").joins(:project)
|
||
|
issues_scope.where("#{project.project_condition(Setting.display_subprojects_issues?)}") if project
|
||
|
result_scope = ActsAsTaggableOn::Tag
|
||
|
.joins(:taggings)
|
||
|
.select('tags.name')
|
||
|
.group('tags.id, tags.name')
|
||
|
.where(taggings: { taggable_type: 'Issue', taggable_id: issues_scope})
|
||
|
.collect {|t| [t.name, t.name]}
|
||
|
result_scope
|
||
|
end
|
||
|
# Adds available filters
|
||
|
def initialize_available_filters
|
||
|
# implemented by sub-classes
|
||
| app/views/issues/_attributes.html.erb | ||
|---|---|---|
|
<%= render :partial => 'issues/form_custom_fields' %>
|
||
|
<% end %>
|
||
|
<p><%= f.text_field :tag_list, :size => 60, :value => @issue.tags.to_s %>
|
||
|
<% end %>
|
||
|
<% include_calendar_headers_tags %>
|
||
| app/views/issues/show.html.erb | ||
|---|---|---|
|
end
|
||
|
end %>
|
||
|
<%= render_half_width_custom_fields_rows(@issue) %>
|
||
|
<% unless @issue.tags.empty? %>
|
||
|
<div class="tags attribute">
|
||
|
<div class="label">
|
||
|
<span><%= l(:field_tags) %>:</span>
|
||
|
</div>
|
||
|
<div class="value">
|
||
|
<%= @issue.tags.to_s %>
|
||
|
</div>
|
||
|
</div>
|
||
|
<% end %>
|
||
|
<%= call_hook(:view_issues_show_details_bottom, :issue => @issue) %>
|
||
|
</div>
|
||
| config/locales/en.yml | ||
|---|---|---|
|
field_recently_used_projects: Number of recently used projects in jump box
|
||
|
field_history_default_tab: Issue's history default tab
|
||
|
field_unique_id: Unique ID
|
||
|
field_tags: Tags
|
||
|
setting_app_title: Application title
|
||
|
setting_welcome_text: Welcome text
|
||
| db/migrate/20180802191932_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb | ||
|---|---|---|
|
# This migration comes from acts_as_taggable_on_engine (originally 1)
|
||
|
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
|
||
|
class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]; end
|
||
|
else
|
||
|
class ActsAsTaggableOnMigration < ActiveRecord::Migration; end
|
||
|
end
|
||
|
ActsAsTaggableOnMigration.class_eval do
|
||
|
def self.up
|
||
|
create_table :tags do |t|
|
||
|
t.string :name
|
||
|
end
|
||
|
create_table :taggings do |t|
|
||
|
t.references :tag
|
||
|
# You should make sure that the column created is
|
||
|
# long enough to store the required class names.
|
||
|
t.references :taggable, polymorphic: true
|
||
|
t.references :tagger, polymorphic: true
|
||
|
# Limit is created to prevent MySQL error on index
|
||
|
# length for MyISAM table type: http://bit.ly/vgW2Ql
|
||
|
t.string :context, limit: 128
|
||
|
t.datetime :created_at
|
||
|
end
|
||
|
add_index :taggings, :tag_id
|
||
|
add_index :taggings, [:taggable_id, :taggable_type, :context]
|
||
|
end
|
||
|
def self.down
|
||
|
drop_table :taggings
|
||
|
drop_table :tags
|
||
|
end
|
||
|
end
|
||
| db/migrate/20180802191933_add_missing_unique_indices.acts_as_taggable_on_engine.rb | ||
|---|---|---|
|
# This migration comes from acts_as_taggable_on_engine (originally 2)
|
||
|
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
|
||
|
class AddMissingUniqueIndices < ActiveRecord::Migration[4.2]; end
|
||
|
else
|
||
|
class AddMissingUniqueIndices < ActiveRecord::Migration; end
|
||
|
end
|
||
|
AddMissingUniqueIndices.class_eval do
|
||
|
def self.up
|
||
|
add_index :tags, :name, unique: true
|
||
|
remove_index :taggings, :tag_id if index_exists?(:taggings, :tag_id)
|
||
|
remove_index :taggings, [:taggable_id, :taggable_type, :context]
|
||
|
add_index :taggings,
|
||
|
[:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type],
|
||
|
unique: true, name: 'taggings_idx'
|
||
|
end
|
||
|
def self.down
|
||
|
remove_index :tags, :name
|
||
|
remove_index :taggings, name: 'taggings_idx'
|
||
|
add_index :taggings, :tag_id unless index_exists?(:taggings, :tag_id)
|
||
|
add_index :taggings, [:taggable_id, :taggable_type, :context]
|
||
|
end
|
||
|
end
|
||
| db/migrate/20180802191934_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb | ||
|---|---|---|
|
# This migration comes from acts_as_taggable_on_engine (originally 3)
|
||
|
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
|
||
|
class AddTaggingsCounterCacheToTags < ActiveRecord::Migration[4.2]; end
|
||
|
else
|
||
|
class AddTaggingsCounterCacheToTags < ActiveRecord::Migration; end
|
||
|
end
|
||
|
AddTaggingsCounterCacheToTags.class_eval do
|
||
|
def self.up
|
||
|
add_column :tags, :taggings_count, :integer, default: 0
|
||
|
ActsAsTaggableOn::Tag.reset_column_information
|
||
|
ActsAsTaggableOn::Tag.find_each do |tag|
|
||
|
ActsAsTaggableOn::Tag.reset_counters(tag.id, :taggings)
|
||
|
end
|
||
|
end
|
||
|
def self.down
|
||
|
remove_column :tags, :taggings_count
|
||
|
end
|
||
|
end
|
||
| db/migrate/20180802191935_add_missing_taggable_index.acts_as_taggable_on_engine.rb | ||
|---|---|---|
|
# This migration comes from acts_as_taggable_on_engine (originally 4)
|
||
|
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
|
||
|
class AddMissingTaggableIndex < ActiveRecord::Migration[4.2]; end
|
||
|
else
|
||
|
class AddMissingTaggableIndex < ActiveRecord::Migration; end
|
||
|
end
|
||
|
AddMissingTaggableIndex.class_eval do
|
||
|
def self.up
|
||
|
add_index :taggings, [:taggable_id, :taggable_type, :context]
|
||
|
end
|
||
|
def self.down
|
||
|
remove_index :taggings, [:taggable_id, :taggable_type, :context]
|
||
|
end
|
||
|
end
|
||
| db/migrate/20180802191936_change_collation_for_tag_names.acts_as_taggable_on_engine.rb | ||
|---|---|---|
|
# This migration comes from acts_as_taggable_on_engine (originally 5)
|
||
|
# This migration is added to circumvent issue #623 and have special characters
|
||
|
# work properly
|
||
|
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
|
||
|
class ChangeCollationForTagNames < ActiveRecord::Migration[4.2]; end
|
||
|
else
|
||
|
class ChangeCollationForTagNames < ActiveRecord::Migration; end
|
||
|
end
|
||
|
ChangeCollationForTagNames.class_eval do
|
||
|
def up
|
||
|
if ActsAsTaggableOn::Utils.using_mysql?
|
||
|
execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| db/migrate/20180802191937_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb | ||
|---|---|---|
|
# This migration comes from acts_as_taggable_on_engine (originally 6)
|
||
|
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
|
||
|
class AddMissingIndexesOnTaggings < ActiveRecord::Migration[4.2]; end
|
||
|
else
|
||
|
class AddMissingIndexesOnTaggings < ActiveRecord::Migration; end
|
||
|
end
|
||
|
AddMissingIndexesOnTaggings.class_eval do
|
||
|
def change
|
||
|
add_index :taggings, :tag_id unless index_exists? :taggings, :tag_id
|
||
|
add_index :taggings, :taggable_id unless index_exists? :taggings, :taggable_id
|
||
|
add_index :taggings, :taggable_type unless index_exists? :taggings, :taggable_type
|
||
|
add_index :taggings, :tagger_id unless index_exists? :taggings, :tagger_id
|
||
|
add_index :taggings, :context unless index_exists? :taggings, :context
|
||
|
unless index_exists? :taggings, [:tagger_id, :tagger_type]
|
||
|
add_index :taggings, [:tagger_id, :tagger_type]
|
||
|
end
|
||
|
unless index_exists? :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy'
|
||
|
add_index :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy'
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| lib/redmine/export/pdf/issues_pdf_helper.rb | ||
|---|---|---|
|
pdf.set_x(base_x)
|
||
|
end
|
||
|
tags = issue.tags
|
||
|
if tags.any?
|
||
|
pdf.SetFontStyle('B',9)
|
||
|
pdf.RDMCell(35+155, 5, l(:field_tags), "LRT", 1)
|
||
|
pdf.SetFontStyle('',9)
|
||
|
pdf.SetFontStyle('',9)
|
||
|
pdf.RDMwriteFormattedCell(35+155, 5, '', '', tags.to_s, '', "LRB")
|
||
|
end
|
||
|
pdf.SetFontStyle('B',9)
|
||
|
pdf.RDMCell(35+155, 5, l(:field_description), "LRT", 1)
|
||
|
pdf.SetFontStyle('',9)
|
||
| ... | ... | |
|
value = " " * level + value
|
||
|
when :attachments
|
||
|
value = value.to_a.map {|a| a.filename}.join("\n")
|
||
|
when :tags
|
||
|
value = value.to_s
|
||
|
end
|
||
|
if value.is_a?(Date)
|
||
|
format_date(value)
|
||
| test/fixtures/taggings.yml | ||
|---|---|---|
|
---
|
||
|
tagging_1:
|
||
|
tag_id: 1
|
||
|
taggable_id: 1
|
||
|
taggable_type: Issue
|
||
|
context: tags
|
||
|
created_at: <%= 3.days.ago.to_s(:db) %>
|
||
|
tagging_2:
|
||
|
tag_id: 2
|
||
|
taggable_id: 1
|
||
|
taggable_type: Issue
|
||
|
context: tags
|
||
|
created_at: <%= 2.days.ago.to_s(:db) %>
|
||
|
tagging_3:
|
||
|
tag_id: 1
|
||
|
taggable_id: 2
|
||
|
taggable_type: Issue
|
||
|
context: tags
|
||
|
created_at: <%= 1.days.ago.to_s(:db) %>
|
||
| test/fixtures/tags.yml | ||
|---|---|---|
|
---
|
||
|
tag_001:
|
||
|
id: 1
|
||
|
name: UX
|
||
|
tag_002:
|
||
|
id: 2
|
||
|
name: Backend
|
||
|
tag_003:
|
||
|
id: 3
|
||
|
name: API
|
||
| test/functional/issues_controller_test.rb | ||
|---|---|---|
|
:queries,
|
||
|
:repositories,
|
||
|
:changesets,
|
||
|
:watchers
|
||
|
:watchers,
|
||
|
:tags,
|
||
|
:taggings
|
||
|
include Redmine::I18n
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
def test_index_with_tags_column
|
||
|
get :index, :params => {
|
||
|
:set_filter => 1,
|
||
|
:project_id => 1,
|
||
|
:c => %w(subject tags)
|
||
|
}
|
||
|
assert_response :success
|
||
|
assert_select 'td.tags', :text => 'UX'
|
||
|
assert_select 'td.tags', :text => 'UX, Backend'
|
||
|
get :index, :params => {
|
||
|
:set_filter => 1,
|
||
|
:project_id => 1,
|
||
|
:c => %w(subject tags),
|
||
|
:format => 'pdf'
|
||
|
}
|
||
|
assert_response :success
|
||
|
assert_equal 'application/pdf', response.content_type
|
||
|
end
|
||
|
def test_show_by_anonymous
|
||
|
get :show, :params => {
|
||
|
:id => 1
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
def test_show_should_render_issue_tags_for_issue_with_tags
|
||
|
@request.session[:user_id] = 1
|
||
|
get :show, :params => {
|
||
|
:id => 1
|
||
|
}
|
||
|
assert_select 'div.tags .value', :text => 'UX, Backend', :count => 1
|
||
|
end
|
||
|
def test_show_should_not_render_issue_tags_for_issue_without_tags
|
||
|
@request.session[:user_id] = 1
|
||
|
get :show, :params => {
|
||
|
:id => 14
|
||
|
}
|
||
|
assert_response :success
|
||
|
assert_select 'div.tags', 0
|
||
|
end
|
||
|
def test_get_new
|
||
|
@request.session[:user_id] = 2
|
||
|
get :new, :params => {
|
||
| ... | ... | |
|
assert_select 'select[name=?]', 'issue[done_ratio]'
|
||
|
assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
|
||
|
assert_select 'input[name=?]', 'issue[watcher_user_ids][]'
|
||
|
assert_select 'input[name=?]', 'issue[tag_list]'
|
||
|
end
|
||
|
# Be sure we don't display inactive IssuePriorities
|
||
| ... | ... | |
|
assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
|
||
|
end
|
||
|
def test_post_create_with_tags
|
||
|
@request.session[:user_id] = 2
|
||
|
post :create, :params => {
|
||
|
:project_id => 1,
|
||
|
:issue => {
|
||
|
:tracker_id => 1,
|
||
|
:subject => 'This is a new issue with tags',
|
||
|
:description => 'This is the description',
|
||
|
:priority_id => 5,
|
||
|
:tag_list => 'One, Two'
|
||
|
}
|
||
|
}
|
||
|
issue = Issue.order('id DESC').first
|
||
|
assert_equal ['One', 'Two'], issue.tag_list
|
||
|
end
|
||
|
def test_post_create_subissue
|
||
|
@request.session[:user_id] = 2
|
||
| ... | ... | |
|
:project_id => '1',
|
||
|
:tracker_id => '2',
|
||
|
:priority_id => '6'
|
||
|
}
|
||
|
}
|
||
|
end
|
||
| ... | ... | |
|
assert_equal 2, issue.reload.assigned_to_id
|
||
|
end
|
||
|
def test_put_update_issue_tags
|
||
|
@request.session[:user_id] = 1
|
||
|
put :update, :params => {
|
||
|
:id => 1,
|
||
|
:issue => {
|
||
|
:tag_list => 'Three'
|
||
|
}
|
||
|
}
|
||
|
assert_response 302
|
||
|
assert_equal ['Three'], Issue.find(1).tag_list
|
||
|
end
|
||
|
def test_get_bulk_edit
|
||
|
@request.session[:user_id] = 2
|
||
|
get :bulk_edit, :params => {
|
||
| test/functional/queries_controller_test.rb | ||
|---|---|---|
|
:members, :member_roles, :roles,
|
||
|
:trackers, :issue_statuses, :issue_categories, :enumerations, :versions,
|
||
|
:issues, :custom_fields, :custom_values,
|
||
|
:queries
|
||
|
:queries, :tags, :taggings
|
||
|
def setup
|
||
|
User.current = nil
|
||
| ... | ... | |
|
assert_include ["Dave Lopper", "3", "active"], json
|
||
|
assert_include ["Dave2 Lopper2", "5", "locked"], json
|
||
|
end
|
||
|
def test_filter_with_tags_should_return_filter_values
|
||
|
@request.session[:user_id] = 2
|
||
|
get :filter, :params => {
|
||
|
:project_id => 1,
|
||
|
:type => 'IssueQuery',
|
||
|
:name => 'tags'
|
||
|
}
|
||
|
assert_response :success
|
||
|
assert_equal 'application/json', response.content_type
|
||
|
json = ActiveSupport::JSON.decode(response.body)
|
||
|
assert_equal [["UX","UX"],["Backend","Backend"]], json
|
||
|
end
|
||
|
end
|
||
| test/unit/issue_tags_test.rb | ||
|---|---|---|
|
# frozen_string_literal: true
|
||
|
# Redmine - project management software
|
||
|
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
require File.expand_path('../../test_helper', __FILE__)
|
||
|
class IssueTagsTest < ActiveSupport::TestCase
|
||
|
fixtures :projects, :users, :email_addresses, :user_preferences, :members, :member_roles, :roles,
|
||
|
:groups_users,
|
||
|
:trackers, :projects_trackers,
|
||
|
:enabled_modules,
|
||
|
:issue_statuses,
|
||
|
:issues, :journals, :journal_details,
|
||
|
:tags, :taggings
|
||
|
include Redmine::I18n
|
||
|
def setup
|
||
|
set_language_if_valid 'en'
|
||
|
end
|
||
|
def teardown
|
||
|
User.current = nil
|
||
|
end
|
||
|
def test_issue_tag_list_should_return_an_array_of_tags
|
||
|
assert_equal ['UX', 'Backend'], Issue.find(1).tags
|
||
|
end
|
||
|
def test_add_issue_tags
|
||
|
issue = Issue.find(2)
|
||
|
issue.tag_list = "One, Two"
|
||
|
assert issue.save
|
||
|
issue.reload
|
||
|
assert_equal ['One', 'Two'], issue.tag_list
|
||
|
end
|
||
|
def test_clear_issue_tags
|
||
|
issue = Issue.find(1)
|
||
|
issue.tag_list = ''
|
||
|
assert issue.save!
|
||
|
assert_equal [], issue.tag_list
|
||
|
end
|
||
|
def test_update_issue_tags_should_journalize_changes
|
||
|
issue = Issue.find(1)
|
||
|
issue.init_journal User.find(1)
|
||
|
issue.tag_list = "UX, API"
|
||
|
assert_difference 'Journal.count', 1 do
|
||
|
assert_difference 'JournalDetail.count', 1 do
|
||
|
issue.save!
|
||
|
end
|
||
|
end
|
||
|
issue.reload
|
||
|
assert_equal ['UX', 'API'], issue.tag_list
|
||
|
detail = JournalDetail.order('id DESC').first
|
||
|
assert_equal issue, detail.journal.journalized
|
||
|
assert_equal 'attr', detail.property
|
||
|
assert_equal 'tags', detail.prop_key
|
||
|
assert_equal 'UX, API', detail.value
|
||
|
assert_equal 'UX, Backend', detail.old_value
|
||
|
end
|
||
|
def test_update_issue_tags_should_not_journalize_changes_if_tags_are_not_changed
|
||
|
issue = Issue.find(1)
|
||
|
issue.init_journal User.find(1)
|
||
|
issue.tag_list = "UX, Backend"
|
||
|
assert_difference 'Journal.count', 0 do
|
||
|
assert_difference 'JournalDetail.count', 0 do
|
||
|
issue.save!
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| test/unit/lib/redmine/export/pdf/issues_pdf_test.rb | ||
|---|---|---|
|
class IssuesPdfHelperTest < ActiveSupport::TestCase
|
||
|
fixtures :users, :projects, :roles, :members, :member_roles,
|
||
|
:enabled_modules, :issues, :trackers, :enumerations
|
||
|
:enabled_modules, :issues, :trackers, :enumerations,
|
||
|
:tags, :taggings
|
||
|
include Redmine::Export::PDF::IssuesPdfHelper
|
||
| ... | ... | |
|
results = fetch_row_values(issue, query, 0)
|
||
|
assert_equal ["2", "Add ingredients categories", "4.34"], results
|
||
|
end
|
||
|
def test_fetch_row_values_should_return_issue_tags_as_string
|
||
|
query = IssueQuery.new(:project => Project.find(1), :name => '_')
|
||
|
query.column_names = [:subject, :tags]
|
||
|
results = fetch_row_values(Issue.find(1), query, 0)
|
||
|
# tags is the third column
|
||
|
tags = results[2]
|
||
|
assert_match 'Backend', tags
|
||
|
assert_match 'UX', tags
|
||
|
end
|
||
|
end
|
||
| test/unit/query_test.rb | ||
|---|---|---|
|
:projects_trackers,
|
||
|
:custom_fields_trackers,
|
||
|
:workflows, :journals,
|
||
|
:attachments, :time_entries
|
||
|
:attachments, :time_entries,
|
||
|
:tags, :taggings
|
||
|
INTEGER_KLASS = RUBY_VERSION >= "2.4" ? Integer : Fixnum
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
def test_filter_by_tags_with_operator_is
|
||
|
query = IssueQuery.new(:name => '_')
|
||
|
filter_name = "tags"
|
||
|
assert_include filter_name, query.available_filters.keys
|
||
|
query.filters = {filter_name => {:operator => '=', :values => ['UX']}}
|
||
|
assert_equal [1, 2], find_issues_with_query(query).map(&:id).sort
|
||
|
# Should return issue tagged with any of the values
|
||
|
query.filters = {filter_name => {:operator => '=', :values => ['UX, Backend']}}
|
||
|
assert_equal [1, 2], find_issues_with_query(query).map(&:id).sort
|
||
|
end
|
||
|
def test_filter_by_tags_with_operator_is_not
|
||
|
query = IssueQuery.new(:name => '_')
|
||
|
filter_name = "tags"
|
||
|
assert_include filter_name, query.available_filters.keys
|
||
|
query.filters = {filter_name => {:operator => '!', :values => ['Backend']}}
|
||
|
issues = find_issues_with_query(query).map(&:id).sort
|
||
|
# Issue tagged with Backend should not be returned
|
||
|
assert_not_include 1, issues
|
||
|
assert_include 2, issues
|
||
|
# Untagged issues should be returned
|
||
|
assert_include 5, issues
|
||
|
end
|
||
|
def test_filter_by_tags_with_operator_none
|
||
|
query = IssueQuery.new(:name => '_')
|
||
|
filter_name = "tags"
|
||
|
assert_include filter_name, query.available_filters.keys
|
||
|
query.filters = {filter_name => {:operator => '!*', :values => ['']}}
|
||
|
issues = find_issues_with_query(query).map(&:id).sort
|
||
|
# Tagged issues should not be returned
|
||
|
assert_not_include 1, issues
|
||
|
assert_not_include 2, issues
|
||
|
# Untagged issues should be returned
|
||
|
assert_include 5, issues
|
||
|
end
|
||
|
def test_filter_by_tags_with_operator_any
|
||
|
query = IssueQuery.new(:name => '_')
|
||
|
filter_name = "tags"
|
||
|
assert_include filter_name, query.available_filters.keys
|
||
|
query.filters = {filter_name => {:operator => '*', :values => ['']}}
|
||
|
assert_equal [1, 2], find_issues_with_query(query).map(&:id).sort
|
||
|
end
|
||
|
def test_user_custom_field_filtered_on_me
|
||
|
User.current = User.find(2)
|
||
|
cf = IssueCustomField.create!(:field_format => 'user', :is_for_all => true, :is_filter => true, :name => 'User custom field', :tracker_ids => [1])
|
||
| ... | ... | |
|
assert_not_nil issues.first.instance_variable_get("@last_notes")
|
||
|
end
|
||
|
def test_query_should_preload_tags
|
||
|
q = IssueQuery.new(:name => '_', :column_names => [:subject, :tags])
|
||
|
assert q.has_column?(:tags)
|
||
|
issues = q.issues
|
||
|
assert_not_nil issues.first.instance_variable_get("@tags")
|
||
|
end
|
||
|
def test_groupable_columns_should_include_custom_fields
|
||
|
q = IssueQuery.new
|
||
|
column = q.groupable_columns.detect {|c| c.name == :cf_1}
|
||
- « Previous
- 1
- …
- 10
- 11
- 12
- Next »