Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix up tests

  • Loading branch information...
commit 9310d2b52bb23e4c06f8065b9c03828e8a80c9b9 1 parent aaefbf0
@melindaweathers melindaweathers authored
Showing with 34 additions and 34 deletions.
  1. +34 −34 test/wherelizer_test.rb
View
68 test/wherelizer_test.rb
@@ -3,59 +3,59 @@
describe Wherelizer do
it 'handles a conditions hash' do
- wherelizer = Wherelizer.new( %q|WikiPage.all(:conditions => {:campaign_id => source_campaign.id, :name => target_names})|)
- assert_equal %q|WikiPage.where(campaign_id: source_campaign.id).where(name: target_names)|, wherelizer.convert
+ wherelizer = Wherelizer.new( %q|Page.all(:conditions => {:content_id => source_content.id, :name => target_names})|)
+ assert_equal %q|Page.where(content_id: source_content.id).where(name: target_names)|, wherelizer.convert
end
it 'handles a numbers and strings as conditions' do
- wherelizer = Wherelizer.new( %q|WikiPage.all(:conditions => {:campaign_id => 5, :name => "Cool"})|)
- assert_equal %q|WikiPage.where(campaign_id: 5).where(name: "Cool")|, wherelizer.convert
+ wherelizer = Wherelizer.new( %q|Page.all(:conditions => {:content_id => 5, :name => "Cool"})|)
+ assert_equal %q|Page.where(content_id: 5).where(name: "Cool")|, wherelizer.convert
end
it 'maintains a query for "first"' do
- wherelizer = Wherelizer.new( %q|WikiPage.first(:conditions => {:campaign_id => source_campaign.id, :name => target_names})|)
- assert_equal %q|WikiPage.where(campaign_id: source_campaign.id).where(name: target_names).first|, wherelizer.convert
+ wherelizer = Wherelizer.new( %q|Page.first(:conditions => {:content_id => source_content.id, :name => target_names})|)
+ assert_equal %q|Page.where(content_id: source_content.id).where(name: target_names).first|, wherelizer.convert
end
it 'handles an order hash' do
- wherelizer = Wherelizer.new( %q|WikiPage.all(:order => 'name asc', :conditions => {:campaign_id => source_campaign.id, :name => target_names})|)
- assert_equal %q|WikiPage.where(campaign_id: source_campaign.id).where(name: target_names).order("name asc")|, wherelizer.convert
+ wherelizer = Wherelizer.new( %q|Page.all(:order => 'name asc', :conditions => {:content_id => source_content.id, :name => target_names})|)
+ assert_equal %q|Page.where(content_id: source_content.id).where(name: target_names).order("name asc")|, wherelizer.convert
end
it 'handles an array conditions with a param.' do
- wherelizer = Wherelizer.new %q|GameContent.all( :conditions => ["campaign_id = ?", source_campaign.id])|
- assert_equal %q|GameContent.where("campaign_id = ?", source_campaign.id)|, wherelizer.convert
+ wherelizer = Wherelizer.new %q|Comment.all( :conditions => ["content_id = ?", source_content.id])|
+ assert_equal %q|Comment.where("content_id = ?", source_content.id)|, wherelizer.convert
end
it 'handles an array conditions with two params.' do
- wherelizer = Wherelizer.new %q|GameContent.all( :conditions => ["campaign_id = ? AND user_id = ?", source_campaign.id, 10])|
- assert_equal %q|GameContent.where("campaign_id = ? AND user_id = ?", source_campaign.id, 10)|, wherelizer.convert
+ wherelizer = Wherelizer.new %q|Comment.all( :conditions => ["content_id = ? AND user_id = ?", source_content.id, 10])|
+ assert_equal %q|Comment.where("content_id = ? AND user_id = ?", source_content.id, 10)|, wherelizer.convert
end
it 'handles an array conditions with no params.' do
- wherelizer = Wherelizer.new %q|GameContent.all( :conditions => ["campaign_id = 10"])|
- assert_equal %q|GameContent.where("campaign_id = 10")|, wherelizer.convert
+ wherelizer = Wherelizer.new %q|Comment.all( :conditions => ["content_id = 10"])|
+ assert_equal %q|Comment.where("content_id = 10")|, wherelizer.convert
end
it 'handles string conditions.' do
- wherelizer = Wherelizer.new %q|GameContent.all( :conditions => "campaign_id = 10")|
- assert_equal %q|GameContent.where("campaign_id = 10")|, wherelizer.convert
+ wherelizer = Wherelizer.new %q|Comment.all( :conditions => "content_id = 10")|
+ assert_equal %q|Comment.where("content_id = 10")|, wherelizer.convert
end
it 'handles a variable assignment in front' do
- wherelizer = Wherelizer.new %q|contents = GameContent.all( :conditions => "campaign_id = 10")|
- assert_equal %q|contents = GameContent.where("campaign_id = 10")|, wherelizer.convert
+ wherelizer = Wherelizer.new %q|comments = Comment.all( :conditions => "content_id = 10")|
+ assert_equal %q|comments = Comment.where("content_id = 10")|, wherelizer.convert
end
it 'handles an instance variable assignment in front' do
- wherelizer = Wherelizer.new %q|@contents = GameContent.all( :conditions => "campaign_id = 10")|
- assert_equal %q|@contents = GameContent.where("campaign_id = 10")|, wherelizer.convert
+ wherelizer = Wherelizer.new %q|@comments = Comment.all( :conditions => "content_id = 10")|
+ assert_equal %q|@comments = Comment.where("content_id = 10")|, wherelizer.convert
end
it 'is idempotent' do
- wherelizer = Wherelizer.new %q|contents = GameContent.all( :conditions => "campaign_id = 10")|
- assert_equal %q|contents = GameContent.where("campaign_id = 10")|, wherelizer.convert
- assert_equal %q|contents = GameContent.where("campaign_id = 10")|, wherelizer.convert
+ wherelizer = Wherelizer.new %q|comments = Comment.all( :conditions => "content_id = 10")|
+ assert_equal %q|comments = Comment.where("content_id = 10")|, wherelizer.convert
+ assert_equal %q|comments = Comment.where("content_id = 10")|, wherelizer.convert
end
it 'handles find(:all)' do
@@ -69,33 +69,33 @@
end
it 'handles select, joins, and group' do
- wherelizer = Wherelizer.new %q|GameSystem.all(:select => 'game_systems.*, count(game_systems.id) AS count', :joins => :campaigns, :group => 'id')|
- assert_equal %q|GameSystem.select("game_systems.*, count(game_systems.id) AS count").joins(:campaigns).group("id")|, wherelizer.convert
+ wherelizer = Wherelizer.new %q|System.all(:select => 'systems.*, count(systems.id) AS count', :joins => :contents, :group => 'id')|
+ assert_equal %q|System.select("systems.*, count(systems.id) AS count").joins(:contents).group("id")|, wherelizer.convert
end
it 'handles include and limit' do
- wherelizer = Wherelizer.new %q|Campaign.all( :conditions => {:id => 1}, :order => "campaigns.id ASC", :include => [:game_master, :game_system], :limit => @limit, :offset => @start)|
- assert_equal %q|Campaign.where(id: 1).order("campaigns.id ASC").includes([:game_master, :game_system]).limit(@limit).offset(@start)|, wherelizer.convert
+ wherelizer = Wherelizer.new %q|Content.all( :conditions => {:id => 1}, :order => "contents.id ASC", :include => [:user, :system], :limit => @limit, :offset => @start)|
+ assert_equal %q|Content.where(id: 1).order("contents.id ASC").includes([:user, :system]).limit(@limit).offset(@start)|, wherelizer.convert
end
it 'handles method calls in receiver' do
- wherelizer = Wherelizer.new %q|@public_pcs = @campaign.game_characters.all(:order => 'id ASC')|
- assert_equal %q|@public_pcs = @campaign.game_characters.order("id ASC")|, wherelizer.convert
+ wherelizer = Wherelizer.new %q|@friend_contents = @content.friends.all(:order => 'id ASC')|
+ assert_equal %q|@friend_contents = @content.friends.order("id ASC")|, wherelizer.convert
end
it 'handles several method calls in receiver' do
- wherelizer = Wherelizer.new %q|@public_pcs = @campaign.parent_campaign.parent_campaign.game_characters.all(:order => 'id ASC')|
- assert_equal %q|@public_pcs = @campaign.parent_campaign.parent_campaign.game_characters.order("id ASC")|, wherelizer.convert
+ wherelizer = Wherelizer.new %q|@friend_contents = @content.parent_content.parent_content.friends.all(:order => 'id ASC')|
+ assert_equal %q|@friend_contents = @content.parent_content.parent_content.friends.order("id ASC")|, wherelizer.convert
end
it 'explains why it cant use a conditions variable' do
skip("TODO: Implement conditions variable usage or a good exception here")
- wherelizer = Wherelizer.new %q|campaigns = Campaign.all( :conditions => conditions, :order => "campaigns.id ASC", :include => [:game_master, :game_system], :limit => @limit, :offset => @start)|
+ wherelizer = Wherelizer.new %q|contents = Content.all( :conditions => conditions, :order => "contents.id ASC", :include => [:user, :system], :limit => @limit, :offset => @start)|
end
it 'handles strings in conditions hash keys' do
- wherelizer = Wherelizer.new( %q|WikiPage.all(:conditions => {'wiki_pages.campaign_id' => 5, :name => "Cool"})|)
- assert_equal %q|WikiPage.where("wiki_pages.campaign_id" => 5).where(name: "Cool")|, wherelizer.convert
+ wherelizer = Wherelizer.new( %q|Page.all(:conditions => {'pages.content_id' => 5, :name => "Cool"})|)
+ assert_equal %q|Page.where("pages.content_id" => 5).where(name: "Cool")|, wherelizer.convert
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.