-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #251 from orgsync/activerecordable
Split our ActiveRecord related methods
- Loading branch information
Showing
5 changed files
with
71 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# coding: utf-8 | ||
|
||
module ActiveInteraction | ||
# Implement the minimal ActiveRecord interface. | ||
# | ||
# @private | ||
module ActiveRecordable | ||
# Returns the column object for the named filter. | ||
# | ||
# @param name [Symbol] The name of a filter. | ||
# | ||
# @example | ||
# class Interaction < ActiveInteraction::Base | ||
# string :email, default: nil | ||
# | ||
# def execute; end | ||
# end | ||
# | ||
# Interaction.new.column_for_attribute(:email) | ||
# # => #<ActiveInteraction::FilterColumn:0x007faebeb2a6c8 @type=:string> | ||
# | ||
# Interaction.new.column_for_attribute(:not_a_filter) | ||
# # => nil | ||
# | ||
# @return [FilterColumn, nil] | ||
# | ||
# @since 1.2.0 | ||
def column_for_attribute(name) | ||
filter = self.class.filters[name] | ||
FilterColumn.intern(filter.database_column_type) if filter | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
spec/active_interaction/concerns/active_recordable_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# coding: utf-8 | ||
|
||
require 'spec_helper' | ||
|
||
InteractionWithFilter = Class.new(TestInteraction) do | ||
float :thing | ||
end | ||
|
||
describe ActiveInteraction::ActiveRecordable do | ||
include_context 'interactions' | ||
|
||
describe '#column_for_attribute(name)' do | ||
let(:described_class) { InteractionWithFilter } | ||
let(:column) { outcome.column_for_attribute(name) } | ||
|
||
context 'name is not an input name' do | ||
let(:name) { SecureRandom.hex } | ||
|
||
it 'returns nil if the attribute cannot be found' do | ||
expect(column).to be_nil | ||
end | ||
end | ||
|
||
context 'name is an input name' do | ||
let(:name) { described_class.filters.keys.first } | ||
|
||
it 'returns a FilterColumn' do | ||
expect(column).to be_a ActiveInteraction::FilterColumn | ||
end | ||
|
||
it 'returns a FilterColumn of type boolean' do | ||
expect(column.type).to eql :float | ||
end | ||
end | ||
end | ||
end |