Remove my custom TimeFilter now that mutations has one on master
parent
91ca6a76ad
commit
9663189a89
2
Gemfile
2
Gemfile
|
@ -6,7 +6,7 @@ gem "thin"
|
|||
gem "rails_12factor"
|
||||
gem "devise"
|
||||
gem "jwt"
|
||||
gem "mutations"
|
||||
gem "mutations", "~> 0.8.0"
|
||||
gem "active_model_serializers", "~> 0.8.3"
|
||||
gem "ice_cube"
|
||||
gem "rack-cors"
|
||||
|
|
|
@ -258,7 +258,7 @@ DEPENDENCIES
|
|||
fog-google!
|
||||
ice_cube
|
||||
jwt
|
||||
mutations
|
||||
mutations (~> 0.8.0)
|
||||
paperclip (~> 5.0.0)
|
||||
pg
|
||||
pry
|
||||
|
@ -280,4 +280,4 @@ RUBY VERSION
|
|||
ruby 2.3.3p222
|
||||
|
||||
BUNDLED WITH
|
||||
1.13.7
|
||||
1.14.1
|
||||
|
|
|
@ -9,22 +9,26 @@ module Api
|
|||
mutate Plants::Create.run(params.as_json, device_params)
|
||||
end
|
||||
|
||||
def update
|
||||
mutate Plants::Update.run(params.as_json, device_params)
|
||||
end
|
||||
|
||||
def destroy
|
||||
if (plant.device == current_device) && plant.destroy
|
||||
render json: ""
|
||||
else
|
||||
raise Errors::Forbidden, "Not your Plant object."
|
||||
end
|
||||
render json: plant.destroy! && ""
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def plants
|
||||
Plant.where(device_params)
|
||||
end
|
||||
|
||||
def device_params
|
||||
@device_params ||= {device: current_device}
|
||||
end
|
||||
|
||||
def plant
|
||||
@plant ||= Plant.find(params[:id])
|
||||
@plant ||= plants.find(params[:id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
# This filter was created by a mutations contributor but was not accepted into
|
||||
# master. I have copy/pasted it here for our own use.
|
||||
module Mutations
|
||||
class TimeFilter < AdditionalFilter
|
||||
@default_options = {
|
||||
nils: false, # allows explicit nil to be valid.
|
||||
format: nil, # If nil then Time.parse else Time.strptime
|
||||
after: nil, # A time object, representing the minimum time allowed
|
||||
before: nil # A time object, representing the maximum time allowed
|
||||
}
|
||||
|
||||
def filter(data)
|
||||
# Handle nil case
|
||||
if data.nil?
|
||||
return [nil, nil] if options[:nils]
|
||||
return [nil, :nils]
|
||||
end
|
||||
|
||||
# Now check if it's empty:
|
||||
return [data, :empty] if data == ""
|
||||
|
||||
if data.is_a?(Time)
|
||||
actual_time = data
|
||||
elsif data.is_a?(String)
|
||||
begin
|
||||
actual_time = if options[:format]
|
||||
Time.strptime(data, options[:format])
|
||||
else
|
||||
Time.parse(data)
|
||||
end
|
||||
rescue ArgumentError
|
||||
return [nil, :time]
|
||||
end
|
||||
elsif data.respond_to?(:to_time) # Time
|
||||
actual_time = data.to_time
|
||||
else
|
||||
return [nil, :time]
|
||||
end
|
||||
|
||||
# Ok, its a valid time, check if it falls within the range
|
||||
if options[:after]
|
||||
if actual_time <= options[:after]
|
||||
return [nil, :after]
|
||||
end
|
||||
end
|
||||
|
||||
if options[:before]
|
||||
if actual_time >= options[:before]
|
||||
return [nil, :before]
|
||||
end
|
||||
end
|
||||
|
||||
# We win, it's valid!
|
||||
[actual_time, nil]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -12,7 +12,7 @@ module Plants
|
|||
string :img_url
|
||||
string :icon_url
|
||||
string :openfarm_slug
|
||||
integer :planted_at
|
||||
time :created_at
|
||||
end
|
||||
|
||||
def execute
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Api::PlantsController do
|
||||
include Devise::Test::ControllerHelpers
|
||||
describe '#update' do
|
||||
# let(:user) { FactoryGirl.create(:user) }
|
||||
# let(:plant) { FactoryGirl.create(:plant, device: user.device) }
|
||||
|
||||
# it 'changes X/Y of a plant' do
|
||||
# sign_in user
|
||||
# patch :update, params: { id: plant.id, x: 4, y: 6 }
|
||||
# binding.pry
|
||||
# expect(response.status).to eq(200)
|
||||
# end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue