Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure segment fields exists. Test segment types.
- Loading branch information
Doug Youch
committed
May 28, 2010
1 parent
ac15a01
commit 51da7c4
Showing
8 changed files
with
194 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,44 @@ | ||
|
||
class EndUserActionSegmentType | ||
|
||
class ActionType < UserSegment::FieldType | ||
class UserActionType < UserSegment::FieldType | ||
include HandlerActions | ||
|
||
def self.select_options(opts={}) | ||
def self.select_options | ||
self.get_handlers(:action).collect { |handler| [handler[1][:description], handler[1][:handler].to_s] } | ||
end | ||
|
||
register_operation :is, [['Action', :model, {:class => EndUserActionSegmentType::ActionType}]] | ||
register_operation :is, [['Action', :model, {:class => EndUserActionSegmentType::UserActionType}]] | ||
|
||
def self.is(cls, field, path) | ||
path = path.split('/') | ||
cls.scoped(:conditions => ["renderer = ? and action = ?", path[0..-2].join('/'), path[-1]]) | ||
cls.scoped(:conditions => ["#{field[0]} = ? and #{field[1]} = ?", path[0..-2].join('/'), path[-1]]) | ||
end | ||
end | ||
|
||
class ActionType < UserSegment::FieldType | ||
|
||
def self.select_options | ||
EndUserAction.find(:all, :select => 'DISTINCT action').collect(&:action).sort | ||
end | ||
|
||
register_operation :is, [['Action', :model, {:class => EndUserActionSegmentType::ActionType}]] | ||
|
||
def self.is(cls, field, action) | ||
cls.scoped(:conditions => ["#{field} = ?", action]) | ||
end | ||
end | ||
|
||
class RendererType < UserSegment::FieldType | ||
|
||
def self.select_options | ||
EndUserAction.find(:all, :select => 'DISTINCT renderer').collect(&:renderer).sort | ||
end | ||
|
||
register_operation :is, [['Renderer', :model, {:class => EndUserActionSegmentType::RendererType}]] | ||
|
||
def self.is(cls, field, renderer) | ||
cls.scoped(:conditions => ["#{field} = ?", renderer]) | ||
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
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,15 @@ | ||
require File.dirname(__FILE__) + "/../spec_helper" | ||
|
||
describe EndUserActionSegmentField do | ||
|
||
it "should only have valid EndUserAction fields" do | ||
obj = EndUserActionSegmentField.user_segment_fields_handler_info[:domain_model_class].new | ||
EndUserActionSegmentField.user_segment_fields.each do |key, value| | ||
if value[:field].is_a?(Array) | ||
value[:field].each { |fld| obj.has_attribute?(fld).should be_true } | ||
else | ||
obj.has_attribute?(value[:field]).should be_true | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require File.dirname(__FILE__) + "/../spec_helper" | ||
|
||
describe EndUserActionSegmentType do | ||
|
||
reset_domain_tables :end_user_actions | ||
|
||
before(:each) do | ||
EndUserAction.create :end_user_id => 1, :renderer => '/editor/auth', :action => 'login' | ||
EndUserAction.create :end_user_id => 2, :renderer => '/editor/auth', :action => 'login' | ||
EndUserAction.create :end_user_id => 3, :renderer => '/editor/auth', :action => 'login' | ||
EndUserAction.create :end_user_id => 4, :renderer => '/editor/auth', :action => 'login' | ||
EndUserAction.create :end_user_id => 5, :renderer => '/editor/auth', :action => 'login' | ||
EndUserAction.create :end_user_id => 5, :renderer => '/editor/auth', :action => 'logout' | ||
EndUserAction.create :end_user_id => 3, :renderer => '/editor/auth', :action => 'logout' | ||
EndUserAction.create :end_user_id => 1, :renderer => '/editor/auth', :action => 'logout' | ||
end | ||
|
||
describe "UserActionType" do | ||
it "should be able to find users" do | ||
@type = EndUserActionSegmentType::UserActionType | ||
@type.select_options | ||
@type.is(EndUserAction, [:renderer, :action], '/editor/auth/login').count.should == 5 | ||
end | ||
end | ||
|
||
describe "ActionType" do | ||
it "should be able to find users" do | ||
@type = EndUserActionSegmentType::ActionType | ||
@type.select_options.length.should == 2 | ||
@type.is(EndUserAction, :action, 'login').count.should == 5 | ||
end | ||
end | ||
|
||
describe "RendererType" do | ||
it "should be able to find users" do | ||
@type = EndUserActionSegmentType::RendererType | ||
@type.select_options.length.should == 1 | ||
@type.is(EndUserAction, :renderer, '/editor/auth').count.should == 8 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require File.dirname(__FILE__) + "/../spec_helper" | ||
|
||
describe EndUserSegmentField do | ||
|
||
reset_domain_tables :end_users | ||
|
||
def field(field, operation, arguments) | ||
arguments = [arguments] unless arguments.is_a?(Array) | ||
@field = UserSegment::Field.new :field => field, :operation => operation, :arguments => arguments | ||
end | ||
|
||
it "should only have valid EndUser fields" do | ||
obj = EndUserSegmentField.user_segment_fields_handler_info[:domain_model_class].new | ||
EndUserSegmentField.user_segment_fields.each do |key, value| | ||
obj.has_attribute?(value[:field]).should be_true | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require File.dirname(__FILE__) + "/../spec_helper" | ||
|
||
describe EndUserSegmentType do | ||
|
||
reset_domain_tables :end_users | ||
|
||
describe "GenderType" do | ||
before(:each) do | ||
EndUser.push_target('test1@test.dev', :gender => 'm') | ||
EndUser.push_target('test2@test.dev', :gender => 'f') | ||
EndUser.push_target('test3@test.dev', :gender => 'f') | ||
|
||
@type = EndUserSegmentType::GenderType | ||
end | ||
|
||
it "should return users using based on gender" do | ||
@type.is(EndUser, :gender, 'm').count.should == 1 | ||
@type.is(EndUser, :gender, 'f').count.should == 2 | ||
end | ||
end | ||
|
||
describe "SourceType" do | ||
before(:each) do | ||
EndUser.push_target('test1@test.dev', :source => 'import') | ||
EndUser.push_target('test2@test.dev', :source => 'import') | ||
EndUser.push_target('test3@test.dev', :source => 'site') | ||
|
||
@type = EndUserSegmentType::SourceType | ||
end | ||
|
||
it "should return users using based on source" do | ||
@type.select_options.length.should == 2 | ||
@type.is(EndUser, :source, 'import').count.should == 2 | ||
@type.is(EndUser, :source, 'site').count.should == 1 | ||
end | ||
end | ||
|
||
describe "LeadSourceType" do | ||
before(:each) do | ||
EndUser.push_target('test1@test.dev', :lead_source => 'import') | ||
EndUser.push_target('test2@test.dev', :lead_source => 'import') | ||
EndUser.push_target('test3@test.dev', :lead_source => 'site') | ||
|
||
@type = EndUserSegmentType::LeadSourceType | ||
end | ||
|
||
it "should return users using based on lead_source" do | ||
@type.select_options.length.should == 2 | ||
@type.is(EndUser, :lead_source, 'import').count.should == 2 | ||
@type.is(EndUser, :lead_source, 'site').count.should == 1 | ||
end | ||
end | ||
end |