Skip to content

Commit ddac9dc

Browse files
committed
Changed created_before to published_before
1 parent 534a3e8 commit ddac9dc

File tree

5 files changed

+15
-18
lines changed

5 files changed

+15
-18
lines changed

app/controllers/api/v1/exercises_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class ExercisesController < OpenStax::Api::V1::ApiController
4545
* `number` &ndash; Matches the exercise number exactly.
4646
* `version` &ndash; Matches the exercise version exactly.
4747
* `id` &ndash; Matches the exercise ID exactly.
48-
* `created_before` &ndash; Matches exercises created before the given date.
49-
Enclose date in quotes to avoid parsing errors.
48+
* `published_before` &ndash; Matches exercises published before the given date.
49+
Enclose date in quotes to avoid parsing errors.
5050
5151
You can also add search terms without prefixes, separated by spaces.
5252
These terms will be searched for in all of the prefix categories.

app/routines/search_exercises.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ class SearchExercises
1010
'number' => Publication.arel_table[:number],
1111
'version' => Publication.arel_table[:version],
1212
'title' => :title,
13-
'created_at' => :created_at
13+
'created_at' => :created_at,
14+
'updated_at' => :updated_at,
15+
'published_at' => Publication.arel_table[:published_at]
1416
}
1517

1618
protected
@@ -189,16 +191,17 @@ def exec(params = {}, options = {})
189191
end
190192
end
191193

192-
with.keyword :created_before do |created_befores|
193-
min_created_before = created_befores.flatten.collect do |str|
194+
with.keyword :published_before do |published_befores|
195+
min_published_before = published_befores.flatten.collect do |str|
194196
DateTime.parse(str) rescue nil
195197
end.compact.min
196-
next @items = @items.none if min_created_before.nil?
198+
next @items = @items.none if min_published_before.nil?
197199

198-
@items = @items.where{created_at < min_created_before}
200+
@items = @items.where{publication.published_at < min_published_before}
199201

200-
# Latest now refers to results that happened before min_created_before
201-
latest_scope = latest_scope.where{created_at < min_created_before} unless latest_scope.nil?
202+
# Latest now refers to results that happened before min_published_before
203+
latest_scope = latest_scope.where{publication.published_at < min_published_before} \
204+
unless latest_scope.nil?
202205
end
203206
end
204207

db/migrate/20150731182709_add_created_at_index_to_exercises.rb

Lines changed: 0 additions & 5 deletions
This file was deleted.

db/schema.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20150731182709) do
14+
ActiveRecord::Schema.define(version: 20150225002247) do
1515

1616
# These are extensions that must be enabled in order to support this database
1717
enable_extension "plpgsql"
@@ -192,7 +192,6 @@
192192
t.datetime "updated_at", null: false
193193
end
194194

195-
add_index "exercises", ["created_at"], name: "index_exercises_on_created_at", using: :btree
196195
add_index "exercises", ["title"], name: "index_exercises_on_title", using: :btree
197196

198197
create_table "fine_print_contracts", force: :cascade do |t|

spec/routines/search_exercises_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
expect(outputs.items).to eq [new_exercise_2]
144144
end
145145

146-
it 'changes the definition of "latest" if created_before is specified' do
146+
it 'changes the definition of "latest" if published_before is specified' do
147147
new_exercise = Exercise.new
148148
Api::V1::ExerciseRepresenter.new(new_exercise).from_json({
149149
tags: ['tag2', 'tag3'],
@@ -179,7 +179,7 @@
179179
expect(outputs.items).to eq []
180180

181181
result = SearchExercises.call(
182-
q: "tag:tAg1 created_before:\"#{new_exercise.created_at.as_json}\""
182+
q: "tag:tAg1 published_before:\"#{new_exercise.published_at.as_json}\""
183183
)
184184
expect(result.errors).to be_empty
185185

0 commit comments

Comments
 (0)