remove references to Warden + JSON field type
did
committed Dec 06, 2016
commit d75b64664a00d7552d90410ffe0a27178ea33a35
Showing 5
changed files with
20 additions
and 61 deletions
locomotive/steam/entities/content_entry.rb b/lib/locomotive/steam/entities/content_entry.rb
+10
-0
| @@ | @@ -132,6 +132,16 @@ module Locomotive::Steam |
| _cast_convertor(field.name, &:to_f) | |
| end | |
| + | def _cast_json(field) |
| + | _cast_convertor(field.name) do |value| |
| + | if value.respond_to?(:to_h) |
| + | value |
| + | else |
| + | value.blank? ? nil : JSON.parse(value) |
| + | end |
| + | end |
| + | end |
| + | |
| def _cast_password(field) | |
| _cast_convertor(:"#{field.name}_hash") do |value| | |
| value.blank? ? nil : BCrypt::Password.new(value) | |
locomotive/steam/initializers.rb b/lib/locomotive/steam/initializers.rb
+0
-1
| @@ | @@ -1,4 +1,3 @@ |
| require_relative 'initializers/sprockets.rb' | |
| require_relative 'initializers/i18n.rb' | |
| require_relative 'initializers/dragonfly.rb' | |
| - | require_relative 'initializers/warden_strategy.rb' |
locomotive/steam/initializers/warden_strategy.rb b/lib/locomotive/steam/initializers/warden_strategy.rb
+0
-40
| @@ | @@ -1,40 +0,0 @@ |
| - | # require 'warden' |
| - | |
| - | # Warden::Strategies.add(:steam_password) do |
| - | |
| - | # def valid? |
| - | # params['auth'].present? |
| - | # end |
| - | |
| - | # def authenticate! |
| - | # puts "[Warden][steam_password] authenticate!" |
| - | # puts params.inspect |
| - | |
| - | # entry = nil |
| - | |
| - | # if type = repositories.content_type.by_slug(params['auth_content_type']) |
| - | # id_field = params['auth_id_field'].try(:to_sym) || :email |
| - | # entry = repositories.content_entry.with(type).all(id_field => params['auth_id']).first |
| - | |
| - | # entry = nil unless entry.password == params['auth_password'] |
| - | # end |
| - | |
| - | # puts "good? #{entry.password == params['auth_password']}" |
| - | |
| - | # entry.nil? ? fail!("Could not log in") : success!(entry) |
| - | |
| - | # # puts entry.name.inspect |
| - | |
| - | # # # TODO |
| - | # # u = User.authenticate(params['username'], params['password']) |
| - | # # u.nil? ? fail!("Could not log in") : success!(u) |
| - | # end |
| - | |
| - | # def services |
| - | # @services ||= env['steam.services'] |
| - | # end |
| - | |
| - | # def repositories |
| - | # @repositories ||= services.repositories |
| - | # end |
| - | # end |
locomotive/steam/middlewares/warden.rb b/lib/locomotive/steam/middlewares/warden.rb
+0
-20
| @@ | @@ -1,20 +0,0 @@ |
| - | # module Locomotive::Steam |
| - | # module Middlewares |
| - | |
| - | # class Warden |
| - | |
| - | # def initialize(app) |
| - | # @warden = ::Warden::Manager.new(app) do |manager| |
| - | # manager.default_strategies :steam_password |
| - | # manager.failure_app = app |
| - | # end |
| - | # end |
| - | |
| - | # def call(env) |
| - | # @warden.call(env) |
| - | # end |
| - | |
| - | # end |
| - | |
| - | # end |
| - | # end |
spec/unit/entities/content_entry_spec.rb
+10
-0
| @@ | @@ -228,6 +228,16 @@ describe Locomotive::Steam::ContentEntry do |
| it { is_expected.to eq({ en: 'Category #1', fr: 'Categorie #1' }) } | |
| end | |
| + | context 'a json' do |
| + | let(:field_type) { :json } |
| + | let(:value) { '{"foo":42}' } |
| + | it { is_expected.to eq({ 'foo' => 42 }) } |
| + | context 'localized' do |
| + | let(:value) { build_i18n_field(en: { 'foo' => 42 }, fr: '[1, 2, 3]') } |
| + | it { expect(subject.translations).to eq('en' => { 'foo' => 42 }, 'fr' => [1, 2, 3]) } |
| + | end |
| + | end |
| + | |
| end | |
| def build_i18n_field(translations = {}) | |