Skip to content
Browse files

Fix up tests & readme

  • Loading branch information...
1 parent aaefbf0 commit 8623c64ba01d85c9e241b7d34e048c7404e21fce @melindaweathers melindaweathers committed
Showing with 40 additions and 40 deletions.
  1. +4 −4 README.md
  2. +34 −34 test/wherelizer_test.rb
  3. +2 −2 wherelizer.gemspec
View
8 README.md
@@ -7,8 +7,8 @@ Tool for converting pre-arel deprecated ActiveRecord queries into new-style Acti
require 'wherelizer'
- Wherelizer.new( %q|WikiPage.all(:conditions => {:campaign_id => 5, :name => "Cool"})| ).convert
- => "WikiPage.where(campaign_id: 5).where(name: \"Cool\")"
+ Wherelizer.new( %q|Page.all(:conditions => {:content_id => 5, :name => "Cool"})| ).convert
+ => "Page.where(content_id: 5).where(name: \"Cool\")"
- Wherelizer.new( %q|@pages = @blog.pages.first(:conditions => {:campaign_id => 5, :name => "Cool"})|).convert
- => "@pages = @blog.pages.where(campaign_id: 5).where(name: \"Cool\").first"
+ Wherelizer.new( %q|@pages = @blog.pages.first(:conditions => {:content_id => 5, :name => "Cool"})|).convert
+ => "@pages = @blog.pages.where(content_id: 5).where(name: \"Cool\").first"
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
View
4 wherelizer.gemspec
@@ -1,8 +1,8 @@
Gem::Specification.new do |s|
s.name = "wherelizer"
- s.version = "0.0.2"
+ s.version = "0.0.4"
s.authors = ["Melinda Weathers"]
- s.date = %q{2013-05-22}
+ s.date = %q{2013-06-05}
s.description = %q{A gem for converting pre-arel ActiveRecord queries to their non-deprecated equivalents}
s.email = %q{melinda@agileleague.com}
s.files = ["lib/wherelizer.rb", "lib/wherelizer/sexp_extensions.rb"]

0 comments on commit 8623c64

Please sign in to comment.
Something went wrong with that request. Please try again.