Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
parterburn committed Jan 18, 2025
1 parent dd63a21 commit 61891cd
Showing 2 changed files with 20 additions and 15 deletions.
28 changes: 14 additions & 14 deletions app/controllers/entries_controller.rb
Original file line number Diff line number Diff line change
@@ -217,20 +217,20 @@ def destroy
def export
if params[:only_images] == "true"
@entries = current_user.entries.only_images.sort_by(&:date)
elsif search_params[:term].present? && search_params[:term].include?(" OR ")
@search = Search.new(search_params)
filter_names = search_params[:term].split(' OR ')
sanitized_terms = filter_names.map { |term| ActiveRecord::Base.sanitize_sql_like(term) }
conditions = sanitized_terms.map { |term| @entries.where("LOWER(entries.body) LIKE ?", "%#{term}%") }
@entries = conditions.reduce(:or)
elsif search_params[:term].present? && search_params[:term].include?('"')
@search = Search.new(search_params)
exact_phrase = search_params[:term].delete('"')
sanitized_phrase = Regexp.escape(exact_phrase)
@entries = current_user.entries.where("entries.body ~* ?", "\\m#{sanitized_phrase}\\M")
elsif search_params[:term].present?
@search = Search.new(search_params)
@entries = @search.entries
elsif params[:search].present? && search_params[:term].present?
if search_params[:term].include?(" OR ")
filter_names = search_params[:term].split(' OR ')
sanitized_terms = filter_names.map { |term| ActiveRecord::Base.sanitize_sql_like(term) }
conditions = sanitized_terms.map { |term| @entries.where("LOWER(entries.body) LIKE ?", "%#{term}%") }
@entries = conditions.reduce(:or)
elsif search_params[:term].include?('"')
exact_phrase = search_params[:term].delete('"')
sanitized_phrase = Regexp.escape(exact_phrase)
@entries = current_user.entries.where("entries.body ~* ?", "\\m#{sanitized_phrase}\\M")
else
@search = Search.new(search_params)
@entries = @search.entries
end
else
@entries = current_user.entries.sort_by(&:date)
end
7 changes: 6 additions & 1 deletion spec/features/entries_spec.rb
Original file line number Diff line number Diff line change
@@ -34,10 +34,15 @@
it 'should not show me other users entries' do
sign_in user
visit group_entries_url(group: not_my_entry.id)
expect(page).to have_content 'No entry found.'
expect(page).to_not have_content not_my_entry.body
end

it 'should not show me other users entries in edit mode' do
sign_in user
visit edit_entry_url(not_my_entry)
expect(page).to have_content 'Not authorized'
end

it 'should show me the calendar with my entries', js: true do
sign_in paid_user
entry.update(date: Date.today, image: nil)

0 comments on commit 61891cd

Please sign in to comment.