@@ -126,10 +126,7 @@ defmodule Ecto.Integration.TimestampsTest do
126
126
test "insert and fetch nil values" do
127
127
now = DateTime . utc_now ( )
128
128
129
- { :ok , product } =
130
- % Product { }
131
- |> Product . changeset ( % { name: "Nil Date Test" , approved_at: now , ordered_at: now } )
132
- |> TestRepo . insert ( )
129
+ product = insert_product ( % { name: "Nil Date Test" , approved_at: now , ordered_at: now } )
133
130
134
131
product = TestRepo . get ( Product , product . id )
135
132
assert product . name == "Nil Date Test"
@@ -146,34 +143,25 @@ defmodule Ecto.Integration.TimestampsTest do
146
143
end
147
144
148
145
test "datetime comparisons" do
149
- account =
150
- % Account { }
151
- |> Account . changeset ( % { name: "Test" } )
152
- |> TestRepo . insert! ( )
146
+ account = insert_account ( % { name: "Test" } )
153
147
154
- % Product { }
155
- |> Product . changeset ( % {
148
+ insert_product ( % {
156
149
account_id: account . id ,
157
150
name: "Foo" ,
158
151
approved_at: ~U[ 2023-01-01T01:00:00Z]
159
152
} )
160
- |> TestRepo . insert! ( )
161
153
162
- % Product { }
163
- |> Product . changeset ( % {
154
+ insert_product ( % {
164
155
account_id: account . id ,
165
156
name: "Bar" ,
166
157
approved_at: ~U[ 2023-01-01T02:00:00Z]
167
158
} )
168
- |> TestRepo . insert! ( )
169
159
170
- % Product { }
171
- |> Product . changeset ( % {
160
+ insert_product ( % {
172
161
account_id: account . id ,
173
162
name: "Qux" ,
174
163
approved_at: ~U[ 2023-01-01T03:00:00Z]
175
164
} )
176
- |> TestRepo . insert! ( )
177
165
178
166
since = ~U[ 2023-01-01T01:59:00Z]
179
167
@@ -187,4 +175,16 @@ defmodule Ecto.Integration.TimestampsTest do
187
175
|> order_by ( [ p ] , desc: p . approved_at )
188
176
|> TestRepo . all ( )
189
177
end
178
+
179
+ defp insert_account ( attrs ) do
180
+ % Account { }
181
+ |> Account . changeset ( attrs )
182
+ |> TestRepo . insert! ( )
183
+ end
184
+
185
+ defp insert_product ( attrs ) do
186
+ % Product { }
187
+ |> Product . changeset ( attrs )
188
+ |> TestRepo . insert! ( )
189
+ end
190
190
end
0 commit comments