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

Normalize rspec syntax to remove deprecation warnings #26

Merged
merged 2 commits into from
Aug 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions spec/active_force/active_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
describe ActiveForce::ActiveQuery do
let(:sobject){
sobject = double("sobject")
sobject.stub(:table_name).and_return "table_name"
sobject.stub(:fields).and_return []
sobject.stub(:mappings).and_return({field: "Field__c"})
allow(sobject).to receive(:table_name).and_return "table_name"
allow(sobject).to receive(:fields).and_return []
allow(sobject).to receive(:mappings).and_return({field: "Field__c"})
sobject
}

let(:client){
double("client")
}

let(:active_query){ ActiveForce::ActiveQuery.new(sobject) }

before do
@active_query = ActiveForce::ActiveQuery.new(sobject)
@active_query.stub(:sfdc_client).and_return client
@active_query.stub(:build).and_return Object.new
allow(active_query).to receive(:sfdc_client).and_return client
allow(active_query).to receive(:build).and_return Object.new
end

describe "to_a" do
Expand All @@ -26,47 +27,47 @@
end

it "should return an array of objects" do
result = @active_query.where("Text_Label = 'foo'").to_a
result = active_query.where("Text_Label = 'foo'").to_a
expect(result).to be_a Array
end

it "should allow to chain query methods" do
result = @active_query.where("Text_Label = 'foo'").where("Checkbox_Label = true").to_a
result = active_query.where("Text_Label = 'foo'").where("Checkbox_Label = true").to_a
expect(result).to be_a Array
end
end

describe "condition mapping" do
it "maps conditions for a .where" do
@active_query.where(field: 123)
expect(@active_query.to_s).to eq("SELECT Id FROM table_name WHERE Field__c = 123")
active_query.where(field: 123)
expect(active_query.to_s).to eq("SELECT Id FROM table_name WHERE Field__c = 123")
end

it "encloses the value in quotes if it's a string" do
@active_query.where field: "hello"
expect(@active_query.to_s).to end_with("Field__c = 'hello'")
active_query.where field: "hello"
expect(active_query.to_s).to end_with("Field__c = 'hello'")
end
end

describe "#find_by" do
it "should query the client, with the SFDC field names and correctly enclosed values" do
expect(client).to receive :query
@active_query.find_by field: 123
expect(@active_query.to_s).to eq "SELECT Id FROM table_name WHERE Field__c = 123 LIMIT 1"
active_query.find_by field: 123
expect(active_query.to_s).to eq "SELECT Id FROM table_name WHERE Field__c = 123 LIMIT 1"
end
end

describe "responding as an enumerable" do
before do
expect(@active_query).to receive(:to_a).and_return([])
expect(active_query).to receive(:to_a).and_return([])
end

it "should call to_a when receiving each" do
@active_query.each {}
active_query.each {}
end

it "should call to_a when receiving map" do
@active_query.map {}
active_query.map {}
end
end
end
36 changes: 18 additions & 18 deletions spec/active_force/association_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

let :post do
post = Post.new
post.stub(:id).and_return "1"
allow(post).to receive(:id).and_return "1"
post
end

let :comment do
comment = Comment.new
comment.stub(:id).and_return "1"
comment.stub(:post_id).and_return "1"
allow(comment).to receive(:id).and_return "1"
allow(comment).to receive(:post_id).and_return "1"
comment
end

Expand All @@ -30,7 +30,7 @@ class Comment < ActiveForce::SObject
self.table_name = "Comment__c"
end

ActiveForce::SObject.stub(:sfdc_client).and_return client
allow(ActiveForce::SObject).to receive(:sfdc_client).and_return client
end

describe "has_many_query" do
Expand All @@ -50,9 +50,9 @@ class Post < ActiveForce::SObject
end

describe 'to_s' do
it "should retrun a OSQL statment" do
post.comments.to_s.should ==
"SELECT Id, PostId FROM Comment__c WHERE PostId = '1'"
it "should retrun a SOQL statment" do
soql = "SELECT Id, PostId FROM Comment__c WHERE PostId = '1'"
expect(post.comments.to_s).to eq soql
end
end

Expand All @@ -65,34 +65,34 @@ class Post < ActiveForce::SObject

it 'should allow to send a different query table name' do
Post.has_many :ugly_comments, { model: Comment }
post.ugly_comments.to_s.should ==
"SELECT Id, PostId FROM Comment__c WHERE PostId = '1'"
soql = "SELECT Id, PostId FROM Comment__c WHERE PostId = '1'"
expect(post.ugly_comments.to_s).to eq soql
end

it 'should allow to change the foreign key' do
Post.has_many :comments, { foreign_key: :post }
Comment.field :post, from: 'PostId'
post.comments.to_s.should ==
"SELECT Id, PostId FROM Comment__c WHERE PostId = '1'"
soql = "SELECT Id, PostId FROM Comment__c WHERE PostId = '1'"
expect(post.comments.to_s).to eq soql
end

it 'should allow to add a where condition' do
Post.has_many :comments, { where: '1 = 1' }
post.comments.to_s.should ==
"SELECT Id, PostId FROM Comment__c WHERE 1 = 1 AND PostId = '1'"
soql = "SELECT Id, PostId FROM Comment__c WHERE 1 = 1 AND PostId = '1'"
expect(post.comments.to_s).to eq soql
end

it 'should use a convention name for the foreign key' do
post.comments.to_s.should ==
"SELECT Id, PostId FROM Comment__c WHERE PostId = '1'"
soql = "SELECT Id, PostId FROM Comment__c WHERE PostId = '1'"
expect(post.comments.to_s).to eq soql
end

end

describe "belongs_to" do

before do
client.stub(:query).and_return Restforce::Mash.new(id: 1)
allow(client).to receive(:query).and_return Restforce::Mash.new(id: 1)
end

it "should get the resource it belongs to" do
Expand All @@ -105,8 +105,8 @@ class Comment < ActiveForce::SObject
field :fancy_post_id, from: 'PostId'
belongs_to :post, foreign_key: :fancy_post_id
end
comment.stub(:fancy_post_id).and_return "2"
client.should_receive(:query).with("SELECT Id FROM Post__c WHERE Id = '2' LIMIT 1")
allow(comment).to receive(:fancy_post_id).and_return "2"
expect(client).to receive(:query).with("SELECT Id FROM Post__c WHERE Id = '2' LIMIT 1")
comment.post
end

Expand Down
55 changes: 22 additions & 33 deletions spec/active_force/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,74 @@

describe ".all" do
it "table should return table name" do
@query.all.table.should be(@query.table)
expect(@query.all.table).to eq(@query.table)
end

it "fields should return fields" do
@query.all.fields.should == @query.fields
expect(@query.all.fields).to eq @query.fields
end
end

describe ".all.to_s" do
it "should return a query for all records" do
@query.all.to_s.should == "SELECT Id, name, etc FROM table_name"
expect(@query.all.to_s).to eq "SELECT Id, name, etc FROM table_name"
end

it "should ignore dupicated attributes in select statment" do
@query.fields ['Id', 'name', 'etc']
@query.all.to_s.should == "SELECT Id, name, etc FROM table_name"
expect(@query.all.to_s).to eq "SELECT Id, name, etc FROM table_name"
end
end

describe ".where" do
it "should add a where condition to a query" do
@query.where("name like '%a%'").to_s.should == "SELECT Id, name, etc FROM table_name WHERE name like '%a%'"
expect(@query.where("name like '%a%'").to_s).to eq "SELECT Id, name, etc FROM table_name WHERE name like '%a%'"
end

it "should add multiples conditions to a query" do
@query.where("condition1 = 1").where("condition2 = 2").to_s.should ==
"SELECT Id, name, etc FROM table_name WHERE condition1 = 1 AND condition2 = 2"
expect(@query.where("condition1 = 1").where("condition2 = 2").to_s).to eq "SELECT Id, name, etc FROM table_name WHERE condition1 = 1 AND condition2 = 2"
end
end

describe ".limit" do
it "should add a limit to a query" do
@query.limit("25").to_s.should == "SELECT Id, name, etc FROM table_name LIMIT 25"
expect(@query.limit("25").to_s).to eq "SELECT Id, name, etc FROM table_name LIMIT 25"
end
end

describe ".limit_value" do
it "should return the limit value" do
@query.limit(4)
@query.limit_value.should == 4
expect(@query.limit_value).to eq 4
end
end

describe ".offset" do
it "should add an offset to a query" do
@query.offset(4).to_s.should == "SELECT Id, name, etc FROM table_name OFFSET 4"
expect(@query.offset(4).to_s).to eq "SELECT Id, name, etc FROM table_name OFFSET 4"
end
end

describe ".offset_value" do
it "should return the offset value" do
@query.offset(4)
@query.offset_value.should == 4
expect(@query.offset_value).to eq 4
end
end

describe ".find.to_s" do
it "should return a query for 1 record" do
@query.find(2).to_s.should == "SELECT Id, name, etc FROM table_name WHERE Id = '2' LIMIT 1"
expect(@query.find(2).to_s).to eq "SELECT Id, name, etc FROM table_name WHERE Id = '2' LIMIT 1"
end
end

describe ".order" do
it "should add a order condition in the statment" do
@query.order("name desc").to_s.should == "SELECT Id, name, etc FROM table_name ORDER BY name desc"
expect(@query.order("name desc").to_s).to eq "SELECT Id, name, etc FROM table_name ORDER BY name desc"
end

it "should add a order condition in the statment with WHERE and LIMIT" do
@query.where("condition1 = 1").order("name desc").limit(1).to_s.should ==
"SELECT Id, name, etc FROM table_name WHERE condition1 = 1 ORDER BY name desc LIMIT 1"
expect(@query.where("condition1 = 1").order("name desc").limit(1).to_s).to eq "SELECT Id, name, etc FROM table_name WHERE condition1 = 1 ORDER BY name desc LIMIT 1"
end
end

Expand All @@ -94,56 +92,47 @@
end

it 'should add another select statment on the current select' do
@query.join(@join).to_s.should ==
'SELECT Id, name, etc, (SELECT Id, name, etc FROM join_table_name) FROM table_name'
expect(@query.join(@join).to_s).to eq 'SELECT Id, name, etc, (SELECT Id, name, etc FROM join_table_name) FROM table_name'
end
end

describe '.first' do
it 'should return the query for the first record' do
@query.first.to_s.should ==
'SELECT Id, name, etc FROM table_name LIMIT 1'
expect(@query.first.to_s).to eq 'SELECT Id, name, etc FROM table_name LIMIT 1'
end
end

describe '.last' do
it 'should return the query for the last record' do
@query.last.to_s.should ==
'SELECT Id, name, etc FROM table_name ORDER BY Id DESC LIMIT 1'
expect(@query.last.to_s).to eq 'SELECT Id, name, etc FROM table_name ORDER BY Id DESC LIMIT 1'
end
end

describe ".count" do
it "should return the query for getting the row count" do
@query.count.to_s.should ==
'SELECT count(Id) FROM table_name'
expect(@query.count.to_s).to eq 'SELECT count(Id) FROM table_name'
end

it "should work with a condition" do
@query.where("name = 'cool'").count.to_s.should ==
"SELECT count(Id) FROM table_name WHERE name = 'cool'"
expect(@query.where("name = 'cool'").count.to_s).to eq "SELECT count(Id) FROM table_name WHERE name = 'cool'"
end
end

describe '.options' do
it 'should add a where if the option has a where condition' do
@query.options(where: 'var = 1').to_s.should ==
"SELECT Id, name, etc FROM table_name WHERE var = 1"
expect(@query.options(where: 'var = 1').to_s).to eq "SELECT Id, name, etc FROM table_name WHERE var = 1"
end

it 'should add a limit if the option has a limit condition' do
@query.options(limit: 1).to_s.should ==
"SELECT Id, name, etc FROM table_name LIMIT 1"
expect(@query.options(limit: 1).to_s).to eq "SELECT Id, name, etc FROM table_name LIMIT 1"
end

it 'should add a order if the option has a order condition' do
@query.options(order: 'name desc').to_s.should ==
"SELECT Id, name, etc FROM table_name ORDER BY name desc"
expect(@query.options(order: 'name desc').to_s).to eq "SELECT Id, name, etc FROM table_name ORDER BY name desc"
end

it 'should work with multiples options' do
@query.options(where: 'var = 1', order: 'name desc', limit: 1).to_s.should ==
"SELECT Id, name, etc FROM table_name WHERE var = 1 ORDER BY name desc LIMIT 1"
expect(@query.options(where: 'var = 1', order: 'name desc', limit: 1).to_s).to eq "SELECT Id, name, etc FROM table_name WHERE var = 1 ORDER BY name desc LIMIT 1"
end
end
end
12 changes: 6 additions & 6 deletions spec/active_force/sobject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let(:client) { double 'Client' }

before do
ActiveForce::SObject.stub(:sfdc_client).and_return client
allow(ActiveForce::SObject).to receive(:sfdc_client).and_return client
end

describe ".new" do
Expand Down Expand Up @@ -52,7 +52,7 @@
end

before do
client.should_receive(:update!).and_return('id')
expect(client).to receive(:update!).and_return('id')
end

it 'delegates to the Client with create!' do
Expand All @@ -68,7 +68,7 @@
end

before do
client.should_receive(:create!).and_return('id')
expect(client).to receive(:create!).and_return('id')
end

it 'delegates to the Client with create!' do
Expand All @@ -85,7 +85,7 @@
describe 'self.create' do

before do
client.should_receive(:create!).and_return('id')
expect(client).to receive(:create!).and_return('id')
end

it 'should create a new instance' do
Expand All @@ -98,7 +98,7 @@
let(:count_response){ [Restforce::Mash.new(expr0: 1)] }

it "responds to count" do
Whizbang.should respond_to(:count)
expect(Whizbang).to respond_to(:count)
end

it "sends the query to the client" do
Expand All @@ -110,7 +110,7 @@

describe "#find_by" do
it "should query the client, with the SFDC field names and correctly enclosed values" do
client.should_receive(:query).with("SELECT #{Whizbang.fields.join ', '} FROM Whizbang__c WHERE Id = 123 AND Text_Label = 'foo' LIMIT 1")
expect(client).to receive(:query).with("SELECT #{Whizbang.fields.join ', '} FROM Whizbang__c WHERE Id = 123 AND Text_Label = 'foo' LIMIT 1")
Whizbang.find_by id: 123, text: "foo"
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/active_force_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

describe ActiveForce do
it 'should have a version number' do
ActiveForce::VERSION.should_not be_nil
expect(ActiveForce::VERSION).to_not be_nil
end
end