Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #29 from dsalahutdinov/master
Browse files Browse the repository at this point in the history
feature: logux actions behaive as action params
  • Loading branch information
dsalahutdinov committed Nov 8, 2018
2 parents cff0b87 + 14961be commit 01689f4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
1 change: 1 addition & 0 deletions lib/logux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'rest-client'
require 'rails/engine'
require 'active_support'
require 'action_controller'
require 'hashie/mash'
require 'logux/engine'
require 'nanoid'
Expand Down
12 changes: 7 additions & 5 deletions lib/logux/actions.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# frozen_string_literal: true

module Logux
class Actions < Hashie::Mash
disable_warnings

class Actions < ::ActionController::Parameters
def action_name
type&.split('/')&.dig(0)
end
Expand All @@ -20,8 +18,12 @@ def channel_id
channel&.split('/')&.last
end

def to_s
to_h.to_s
def type
require(:type)
end

def channel
require(:channel)
end
end
end
30 changes: 19 additions & 11 deletions spec/factories/logux_actions_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,40 @@
factory :logux_actions, class: Logux::Actions do
factory :logux_actions_subscribe do
skip_create
type { 'logux/subscribe' }
channel { 'user/1' }
initialize_with do
new({ type: 'logux/subscribe', channel: 'user/1' }.merge(attributes))
end
end

factory :logux_actions_add do
skip_create
type { 'user/add' }
key { 'name' }
value { 'test' }
initialize_with do
new({ type: 'user/add', key: 'name', value: 'test' }.merge(attributes))
end
end

factory :logux_actions_update do
skip_create
type { 'user/update' }
key { 'name' }
value { 'test1' }
initialize_with do
new({ type: 'user/add', key: 'name', value: 'test' }.merge(attributes))
end
end

factory :logux_actions_unknown do
skip_create
type { 'unknown/action' }
initialize_with do
new({ type: 'unknown/action' }.merge(attributes))
end
end

factory :logux_actions_unknown_subscribe do
type { 'logux/subscribe' }
channel { 'unknown/channel' }
skip_create
initialize_with do
new(
{ type: 'logux/subscribe', channel: 'unknown/channel' }
.merge(attributes)
)
end
end
end
end
14 changes: 13 additions & 1 deletion spec/logux/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

describe Logux::Actions do
let(:actions) do
described_class.new(type: 'user/add', channel: 'project/123')
described_class.new(
type: 'user/add', channel: 'project/123', data: 'data'
)
end

describe '#action_type' do
Expand All @@ -30,4 +32,14 @@

it { is_expected.to eq '123' }
end

describe 'permitted attributes' do
it 'has actions params unpermitted' do
expect(actions).not_to be_permitted
end

it 'permits params' do
expect(actions.permit(:data)).to be_permitted
end
end
end
4 changes: 3 additions & 1 deletion spec/logux/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
describe Logux::Client do
let(:client) { described_class.new }
let(:meta) { create(:logux_meta) }
let(:commands) { [['action', { id: 1 }, meta], ['action', { id: 2 }, meta]] }
let(:commands) do
[['action', { id: 1 }, meta], ['action', { id: 2 }, meta]]
end
let(:params) do
{
version: 0,
Expand Down

0 comments on commit 01689f4

Please sign in to comment.