Skip to content

Commit

Permalink
use all tag in downcase see #34
Browse files Browse the repository at this point in the history
  • Loading branch information
shingara committed Mar 1, 2010
1 parent 30e8ec4 commit 3894bc6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/models/ticket.rb
Expand Up @@ -102,7 +102,7 @@ def generate_update(ticket, user)
t.add_update(:tag_list,
Ticket.list_tag(self.tag_list).join(','),
Ticket.list_tag(ticket[:tag_list]).join(','))
self.tag_list = ticket[:tag_list]
self.tag_list = ticket[:tag_list].try(:downcase)
end

[[:state_id, State],
Expand Down Expand Up @@ -146,7 +146,7 @@ def self.paginate_by_search(q, conditions={})
query_conditions[:state_name] = s[1]
elsif s[0] == 'tagged'
query_conditions[:tags] ||= []
query_conditions[:tags] << s[1]
query_conditions[:tags] << s[1].downcase
elsif s[0] == 'closed'
query_conditions[:closed] = (s[1] == 'true')
else
Expand Down Expand Up @@ -175,7 +175,7 @@ def self.new_by_params(params, project, user)

def self.list_tag(string)
string.to_s.split(',').map { |name|
name.gsub(/[^\w_-]/i, '').strip
name.gsub(/[^\w_-]/i, '').strip.downcase
}.uniq.sort
end

Expand Down Expand Up @@ -253,6 +253,7 @@ def copy_user_creator_name

def update_tags
self.tags = Ticket.list_tag(self.tag_list)
self.tag_list = self.tag_list.downcase
end

def update_priority
Expand Down
13 changes: 13 additions & 0 deletions spec/models/ticket_spec.rb
Expand Up @@ -140,6 +140,9 @@ def valid_ticket
Ticket.paginate_by_search("tagged:#{@second_tag} tagged:#{@third_tag}",
:page => 1,
:per_page => 10).sort_by(&:title).should == [@second_ticket, @four_ticket].sort_by(&:title)
Ticket.paginate_by_search("tagged:#{@second_tag.upcase} tagged:#{@third_tag.upcase}",
:page => 1,
:per_page => 10).sort_by(&:title).should == [@second_ticket, @four_ticket].sort_by(&:title)
end

it 'should return all ticket with all tags define by tagged:xxx and state:xxx in query' do
Expand Down Expand Up @@ -592,6 +595,16 @@ def new_by_params(args={})

end
end

describe '#update_tags' do
it 'should save in downcase' do
Ticket.make(:tag_list => 'foo,bar,baz'.upcase).tags.should == Set.new(['bar','baz','foo'])

end
it 'should split tag_list' do
Ticket.make(:tag_list => 'foo,bar,baz').tags.should == Set.new(['bar','baz','foo'])
end
end
end

end

0 comments on commit 3894bc6

Please sign in to comment.