diff --git a/Gemfile.lock b/Gemfile.lock index 4468464d0..6311dd2b4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -301,4 +301,4 @@ DEPENDENCIES xcop (= 0.7.1) BUNDLED WITH - 2.5.3 + 2.4.22 diff --git a/objects/search.rb b/objects/search.rb index 3bf800722..dd5b57c7f 100644 --- a/objects/search.rb +++ b/objects/search.rb @@ -51,6 +51,7 @@ def each 'LEFT JOIN flag ON flag.message = message.id', 'WHERE (bout.owner = $1 OR guest.human = $1)', pred, + 'GROUP BY message.id', 'ORDER BY message.created DESC', "OFFSET #{@offset}", "LIMIT #{@limit}" diff --git a/test/test__helper.rb b/test/test__helper.rb index 502b692e0..9f568e812 100644 --- a/test/test__helper.rb +++ b/test/test__helper.rb @@ -48,7 +48,7 @@ def test_pgsql end def test_name - "jeff#{SecureRandom.hex(4)}" + "jeff#{SecureRandom.hex(8)}" end end end diff --git a/test/test_search.rb b/test/test_search.rb index 929c64039..62b6983a5 100644 --- a/test/test_search.rb +++ b/test/test_search.rb @@ -40,7 +40,7 @@ def test_finds_messages bout = bouts.start(test_name) msg = bout.post('Hey, you!') found = [] - human.search(Nb::Query.new('(text=~you)'), 0, 1).each do |m| + human.search(Nb::Query.new('(text=~you)'), 0, 10).each do |m| found << m end assert_equal(1, found.size) @@ -54,7 +54,7 @@ def test_finds_only_my_messages bout.post(test_name) friend = Nb::Humans.new(test_pgsql).take(test_name).create found = [] - friend.search(Nb::Query.new(''), 0, 1).each do |m| + friend.search(Nb::Query.new(''), 0, 10).each do |m| found << m end assert_equal(0, found.size) @@ -71,7 +71,21 @@ def test_finds_by_tags_and_flags bout.post(test_name).flags.attach('small') bout.post(test_name).flags.attach('medium') found = [] - human.search(Nb::Query.new('(#color=blue and $small+)'), 0, 1).each do |m| + human.search(Nb::Query.new('(#color=blue and $small+)'), 0, 10).each do |m| + found << m + end + assert_equal(1, found.size) + end + + def test_group_by_message + human = Nb::Humans.new(test_pgsql).take(test_name).create + bouts = human.bouts + bout = bouts.start(test_name) + msg = bout.post(test_name) + msg.flags.attach('one') + msg.flags.attach('two') + found = [] + human.search(Nb::Query.new(''), 0, 10).each do |m| found << m end assert_equal(1, found.size) diff --git a/views/inbox.haml b/views/inbox.haml index ac32e0060..3ccec83b3 100644 --- a/views/inbox.haml +++ b/views/inbox.haml @@ -25,14 +25,14 @@ - unless the_bout.nil? %p Tags: - %span.click{onclick: '$("#tags").toggle();'} + %span.click{onclick: '$("#tags").toggle(); $("#tags-name").focus();'} = '+' %br - bout.tags.each do |tag| %code= "#{tag.name}=#{tag.value}" %form{action: iri.cut('/b').append(the_bout).append('/tag'), method: 'post', id: 'tags', style: 'display: none;'} %fieldset - %input{name: 'name', type: 'text', required: true, size: 8, placeholder: 'Tag', tabindex: 3} + %input{name: 'name', type: 'text', required: true, size: 8, placeholder: 'Tag', tabindex: 3, id: 'tags-name'} %input{name: 'value', type: 'text', size: 20, placeholder: 'Value', tabindex: 4} %button{type: 'submit', tabindex: 5} Put @@ -43,11 +43,11 @@ Guests: - bout.guests.each do |guest| %code= "#{guest}" - %span.click{onclick: '$("#invite").toggle();'} + %span.click{onclick: '$("#invite").toggle(); $("#invite-human").focus();'} = '+' %form{action: iri.cut('/b').append(the_bout).append('/invite'), method: 'post', id: 'invite', style: 'display: none;'} %fieldset - %input{name: 'human', type: 'text', required: true, size: 12, placeholder: 'Identity', tabindex: 6} + %input{name: 'human', type: 'text', required: true, size: 12, placeholder: 'Identity', tabindex: 6, id: 'invite-human'} %button{type: 'submit', tabindex: 7} Invite @@ -62,7 +62,7 @@ %code= msg.author.identity on = msg.created - %span.click{onclick: "$('#flags-#{msg.id}').toggle();"} + %span.click{onclick: "$('#flags-#{msg.id}').toggle(); $('#flags-#{msg.id}-name').focus();"} + %br = msg.text @@ -74,7 +74,7 @@ %a.click{href: iri.cut('/m').append(msg.id).append('detach').add(name: flag.name)}= 'x' %form{action: iri.cut('/m').append(msg.id).append('/attach'), method: 'post', id: "flags-#{msg.id}", style: 'display: none;'} %fieldset - %input{name: 'name', type: 'text', required: true, size: 12, placeholder: 'Flag'} + %input{name: 'name', type: 'text', required: true, size: 12, placeholder: 'Flag', id: "flags-#{msg.id}-name"} %button{type: 'submit'} Flag - total += 1