fix rspec deprecate stub
This commit is contained in:
parent
f2cecf3518
commit
558340a610
|
@ -16,14 +16,14 @@ describe DummyController do
|
|||
end
|
||||
|
||||
it "should recognize unique session" do
|
||||
controller.stub!(:session_hash).and_return(request.session_options[:id])
|
||||
controller.stub(:session_hash).and_return(request.session_options[:id])
|
||||
controller.impressionist_subapp_filter(nil, [:session_hash])
|
||||
controller.impressionist_subapp_filter(nil, [:session_hash])
|
||||
Impression.should have(@impression_count + 1).records
|
||||
end
|
||||
|
||||
it "should recognize unique ip" do
|
||||
controller.request.stub!(:remote_ip).and_return("1.2.3.4")
|
||||
controller.request.stub(:remote_ip).and_return("1.2.3.4")
|
||||
controller.impressionist_subapp_filter(nil, [:ip_address])
|
||||
controller.impressionist_subapp_filter(nil, [:ip_address])
|
||||
Impression.should have(@impression_count + 1).records
|
||||
|
@ -36,35 +36,35 @@ describe DummyController do
|
|||
end
|
||||
|
||||
it "should recognize unique action" do
|
||||
controller.stub!(:action_name).and_return("test_action")
|
||||
controller.stub(:action_name).and_return("test_action")
|
||||
controller.impressionist_subapp_filter(nil, [:action_name])
|
||||
controller.impressionist_subapp_filter(nil, [:action_name])
|
||||
Impression.should have(@impression_count + 1).records
|
||||
end
|
||||
|
||||
it "should recognize unique controller" do
|
||||
controller.stub!(:controller_name).and_return("post")
|
||||
controller.stub(:controller_name).and_return("post")
|
||||
controller.impressionist_subapp_filter(nil, [:controller_name])
|
||||
controller.impressionist_subapp_filter(nil, [:controller_name])
|
||||
Impression.should have(@impression_count + 1).records
|
||||
end
|
||||
|
||||
it "should recognize unique user" do
|
||||
controller.stub!(:user_id).and_return(42)
|
||||
controller.stub(:user_id).and_return(42)
|
||||
controller.impressionist_subapp_filter(nil, [:user_id])
|
||||
controller.impressionist_subapp_filter(nil, [:user_id])
|
||||
Impression.should have(@impression_count + 1).records
|
||||
end
|
||||
|
||||
it "should recognize unique referer" do
|
||||
controller.request.stub!(:referer).and_return("http://foo/bar")
|
||||
controller.request.stub(:referer).and_return("http://foo/bar")
|
||||
controller.impressionist_subapp_filter(nil, [:referrer])
|
||||
controller.impressionist_subapp_filter(nil, [:referrer])
|
||||
Impression.should have(@impression_count + 1).records
|
||||
end
|
||||
|
||||
it "should recognize unique id" do
|
||||
controller.stub!(:params).and_return({:id => "666"}) # for correct impressionable id in filter
|
||||
controller.stub(:params).and_return({:id => "666"}) # for correct impressionable id in filter
|
||||
controller.impressionist_subapp_filter(nil, [:impressionable_id])
|
||||
controller.impressionist_subapp_filter(nil, [:impressionable_id])
|
||||
Impression.should have(@impression_count + 1).records
|
||||
|
@ -72,88 +72,88 @@ describe DummyController do
|
|||
|
||||
# extra redundant test for important controller and action combination.
|
||||
it "should recognize different controller and action" do
|
||||
controller.stub!(:controller_name).and_return("post")
|
||||
controller.stub!(:action_name).and_return("test_action")
|
||||
controller.stub(:controller_name).and_return("post")
|
||||
controller.stub(:action_name).and_return("test_action")
|
||||
controller.impressionist_subapp_filter(nil, [:controller_name, :action_name])
|
||||
controller.impressionist_subapp_filter(nil, [:controller_name, :action_name])
|
||||
Impression.should have(@impression_count + 1).records
|
||||
controller.stub!(:action_name).and_return("another_action")
|
||||
controller.stub(:action_name).and_return("another_action")
|
||||
controller.impressionist_subapp_filter(nil, [:controller_name, :action_name])
|
||||
controller.impressionist_subapp_filter(nil, [:controller_name, :action_name])
|
||||
Impression.should have(@impression_count + 2).records
|
||||
controller.stub!(:controller_name).and_return("article")
|
||||
controller.stub(:controller_name).and_return("article")
|
||||
controller.impressionist_subapp_filter(nil, [:controller_name, :action_name])
|
||||
controller.impressionist_subapp_filter(nil, [:controller_name, :action_name])
|
||||
Impression.should have(@impression_count + 3).records
|
||||
end
|
||||
|
||||
it "should recognize different action" do
|
||||
controller.stub!(:action_name).and_return("test_action")
|
||||
controller.stub(:action_name).and_return("test_action")
|
||||
controller.impressionist_subapp_filter(nil, [:action_name])
|
||||
controller.impressionist_subapp_filter(nil, [:action_name])
|
||||
Impression.should have(@impression_count + 1).records
|
||||
controller.stub!(:action_name).and_return("another_action")
|
||||
controller.stub(:action_name).and_return("another_action")
|
||||
controller.impressionist_subapp_filter(nil, [:action_name])
|
||||
controller.impressionist_subapp_filter(nil, [:action_name])
|
||||
Impression.should have(@impression_count + 2).records
|
||||
end
|
||||
|
||||
it "should recognize different controller" do
|
||||
controller.stub!(:controller_name).and_return("post")
|
||||
controller.stub(:controller_name).and_return("post")
|
||||
controller.impressionist_subapp_filter(nil, [:controller_name])
|
||||
controller.impressionist_subapp_filter(nil, [:controller_name])
|
||||
Impression.should have(@impression_count + 1).records
|
||||
controller.stub!(:controller_name).and_return("article")
|
||||
controller.stub(:controller_name).and_return("article")
|
||||
controller.impressionist_subapp_filter(nil, [:controller_name])
|
||||
controller.impressionist_subapp_filter(nil, [:controller_name])
|
||||
Impression.should have(@impression_count + 2).records
|
||||
end
|
||||
|
||||
it "should recognize different session" do
|
||||
controller.stub!(:session_hash).and_return("foo")
|
||||
controller.stub(:session_hash).and_return("foo")
|
||||
controller.impressionist_subapp_filter(nil, [:session_hash])
|
||||
controller.impressionist_subapp_filter(nil, [:session_hash])
|
||||
Impression.should have(@impression_count + 1).records
|
||||
controller.stub!(:session_hash).and_return("bar")
|
||||
controller.stub(:session_hash).and_return("bar")
|
||||
controller.impressionist_subapp_filter(nil, [:session_hash])
|
||||
controller.impressionist_subapp_filter(nil, [:session_hash])
|
||||
Impression.should have(@impression_count + 2).records
|
||||
end
|
||||
|
||||
it "should recognize different ip" do
|
||||
controller.request.stub!(:remote_ip).and_return("1.2.3.4")
|
||||
controller.request.stub(:remote_ip).and_return("1.2.3.4")
|
||||
controller.impressionist_subapp_filter(nil, [:ip_address])
|
||||
controller.impressionist_subapp_filter(nil, [:ip_address])
|
||||
Impression.should have(@impression_count + 1).records
|
||||
controller.request.stub!(:remote_ip).and_return("5.6.7.8")
|
||||
controller.request.stub(:remote_ip).and_return("5.6.7.8")
|
||||
controller.impressionist_subapp_filter(nil, [:ip_address])
|
||||
controller.impressionist_subapp_filter(nil, [:ip_address])
|
||||
Impression.should have(@impression_count + 2).records
|
||||
end
|
||||
|
||||
it "should recognize different referer" do
|
||||
controller.request.stub!(:referer).and_return("http://foo/bar")
|
||||
controller.request.stub(:referer).and_return("http://foo/bar")
|
||||
controller.impressionist_subapp_filter(nil, [:referrer])
|
||||
controller.impressionist_subapp_filter(nil, [:referrer])
|
||||
Impression.should have(@impression_count + 1).records
|
||||
controller.request.stub!(:referer).and_return("http://bar/fo")
|
||||
controller.request.stub(:referer).and_return("http://bar/fo")
|
||||
controller.impressionist_subapp_filter(nil, [:referrer])
|
||||
controller.impressionist_subapp_filter(nil, [:referrer])
|
||||
Impression.should have(@impression_count + 2).records
|
||||
end
|
||||
|
||||
it "should recognize different id" do
|
||||
controller.stub!(:params).and_return({:id => "666"}) # for correct impressionable id in filter
|
||||
controller.stub(:params).and_return({:id => "666"}) # for correct impressionable id in filter
|
||||
controller.impressionist_subapp_filter(nil, [:impressionable_type, :impressionable_id])
|
||||
controller.impressionist_subapp_filter(nil, [:impressionable_type, :impressionable_id])
|
||||
controller.stub!(:params).and_return({:id => "42"}) # for correct impressionable id in filter
|
||||
controller.stub(:params).and_return({:id => "42"}) # for correct impressionable id in filter
|
||||
controller.impressionist_subapp_filter(nil, [:impressionable_type, :impressionable_id])
|
||||
controller.impressionist_subapp_filter(nil, [:impressionable_type, :impressionable_id])
|
||||
Impression.should have(@impression_count + 2).records
|
||||
end
|
||||
|
||||
it "should recognize combined uniqueness" do
|
||||
controller.stub!(:action_name).and_return("test_action")
|
||||
controller.stub(:action_name).and_return("test_action")
|
||||
controller.impressionist_subapp_filter(nil, [:ip_address, :request_hash, :action_name])
|
||||
controller.impressionist_subapp_filter(nil, [:request_hash, :ip_address, :action_name])
|
||||
controller.impressionist_subapp_filter(nil, [:request_hash, :action_name])
|
||||
|
@ -166,11 +166,11 @@ describe DummyController do
|
|||
end
|
||||
|
||||
it "should recognize combined non-uniqueness" do
|
||||
controller.stub!(:action_name).and_return(nil)
|
||||
controller.stub(:action_name).and_return(nil)
|
||||
controller.impressionist_subapp_filter(nil, [:ip_address, :action_name])
|
||||
controller.stub!(:action_name).and_return("test_action")
|
||||
controller.stub(:action_name).and_return("test_action")
|
||||
controller.impressionist_subapp_filter(nil, [:ip_address, :action_name])
|
||||
controller.stub!(:action_name).and_return("another_action")
|
||||
controller.stub(:action_name).and_return("another_action")
|
||||
controller.impressionist_subapp_filter(nil, [:ip_address, :action_name])
|
||||
Impression.should have(@impression_count + 3).records
|
||||
end
|
||||
|
@ -189,7 +189,7 @@ describe DummyController do
|
|||
end
|
||||
|
||||
it "should recognize unique session" do
|
||||
controller.stub!(:session_hash).and_return(request.session_options[:id])
|
||||
controller.stub(:session_hash).and_return(request.session_options[:id])
|
||||
impressionable = Post.create
|
||||
controller.impressionist(impressionable, nil, :unique => [:session_hash])
|
||||
controller.impressionist(impressionable, nil, :unique => [:session_hash])
|
||||
|
@ -197,7 +197,7 @@ describe DummyController do
|
|||
end
|
||||
|
||||
it "should recognize unique ip" do
|
||||
controller.request.stub!(:remote_ip).and_return("1.2.3.4")
|
||||
controller.request.stub(:remote_ip).and_return("1.2.3.4")
|
||||
impressionable = Post.create
|
||||
controller.impressionist(impressionable, nil, :unique => [:ip_address])
|
||||
controller.impressionist(impressionable, nil, :unique => [:ip_address])
|
||||
|
@ -212,7 +212,7 @@ describe DummyController do
|
|||
end
|
||||
|
||||
it "should recognize unique user" do
|
||||
controller.stub!(:user_id).and_return(666)
|
||||
controller.stub(:user_id).and_return(666)
|
||||
impressionable = Post.create
|
||||
controller.impressionist(impressionable, nil, :unique => [:user_id])
|
||||
controller.impressionist(impressionable, nil, :unique => [:user_id])
|
||||
|
@ -220,7 +220,7 @@ describe DummyController do
|
|||
end
|
||||
|
||||
it "should recognize unique referer" do
|
||||
controller.request.stub!(:referer).and_return("http://foo/bar")
|
||||
controller.request.stub(:referer).and_return("http://foo/bar")
|
||||
impressionable = Post.create
|
||||
controller.impressionist(impressionable, nil, :unique => [:referrer])
|
||||
controller.impressionist(impressionable, nil, :unique => [:referrer])
|
||||
|
@ -229,23 +229,23 @@ describe DummyController do
|
|||
|
||||
it "should recognize different session" do
|
||||
impressionable = Post.create
|
||||
controller.stub!(:session_hash).and_return("foo")
|
||||
controller.stub(:session_hash).and_return("foo")
|
||||
controller.impressionist(impressionable, nil, :unique => [:session_hash])
|
||||
controller.impressionist(impressionable, nil, :unique => [:session_hash])
|
||||
Impression.should have(@impression_count + 1).records
|
||||
controller.stub!(:session_hash).and_return("bar")
|
||||
controller.stub(:session_hash).and_return("bar")
|
||||
controller.impressionist(impressionable, nil, :unique => [:session_hash])
|
||||
controller.impressionist(impressionable, nil, :unique => [:session_hash])
|
||||
Impression.should have(@impression_count + 2).records
|
||||
end
|
||||
|
||||
it "should recognize different ip" do
|
||||
controller.request.stub!(:remote_ip).and_return("1.2.3.4")
|
||||
controller.request.stub(:remote_ip).and_return("1.2.3.4")
|
||||
impressionable = Post.create
|
||||
controller.impressionist(impressionable, nil, :unique => [:ip_address])
|
||||
controller.impressionist(impressionable, nil, :unique => [:ip_address])
|
||||
Impression.should have(@impression_count + 1).records
|
||||
controller.request.stub!(:remote_ip).and_return("5.6.7.8")
|
||||
controller.request.stub(:remote_ip).and_return("5.6.7.8")
|
||||
controller.impressionist(impressionable, nil, :unique => [:ip_address])
|
||||
controller.impressionist(impressionable, nil, :unique => [:ip_address])
|
||||
Impression.should have(@impression_count + 2).records
|
||||
|
@ -253,11 +253,11 @@ describe DummyController do
|
|||
|
||||
it "should recognize different user" do
|
||||
impressionable = Post.create
|
||||
controller.stub!(:user_id).and_return(666)
|
||||
controller.stub(:user_id).and_return(666)
|
||||
controller.impressionist(impressionable, nil, :unique => [:user_id])
|
||||
controller.impressionist(impressionable, nil, :unique => [:user_id])
|
||||
Impression.should have(@impression_count + 1).records
|
||||
controller.stub!(:user_id).and_return(42)
|
||||
controller.stub(:user_id).and_return(42)
|
||||
controller.impressionist(impressionable, nil, :unique => [:user_id])
|
||||
controller.impressionist(impressionable, nil, :unique => [:user_id])
|
||||
Impression.should have(@impression_count + 2).records
|
||||
|
@ -265,7 +265,7 @@ describe DummyController do
|
|||
|
||||
it "should recognize combined uniqueness" do
|
||||
impressionable = Post.create
|
||||
controller.stub!(:session_hash).and_return("foo")
|
||||
controller.stub(:session_hash).and_return("foo")
|
||||
controller.impressionist(impressionable, nil, :unique => [:ip_address, :request_hash, :session_hash])
|
||||
controller.impressionist(impressionable, nil, :unique => [:request_hash, :ip_address, :session_hash])
|
||||
controller.impressionist(impressionable, nil, :unique => [:request_hash, :session_hash])
|
||||
|
@ -279,11 +279,11 @@ describe DummyController do
|
|||
|
||||
it "should recognize combined non-uniqueness" do
|
||||
impressionable = Post.create
|
||||
controller.stub!(:session_hash).and_return(nil)
|
||||
controller.stub(:session_hash).and_return(nil)
|
||||
controller.impressionist(impressionable, nil, :unique => [:ip_address, :session_hash])
|
||||
controller.stub!(:session_hash).and_return("foo")
|
||||
controller.stub(:session_hash).and_return("foo")
|
||||
controller.impressionist(impressionable, nil, :unique => [:ip_address, :session_hash])
|
||||
controller.stub!(:session_hash).and_return("bar")
|
||||
controller.stub(:session_hash).and_return("bar")
|
||||
controller.impressionist(impressionable, nil, :unique => [:ip_address, :session_hash])
|
||||
Impression.should have(@impression_count + 3).records
|
||||
end
|
||||
|
@ -294,10 +294,10 @@ describe DummyController do
|
|||
|
||||
it "should recognize uniqueness" do
|
||||
impressionable = Post.create
|
||||
controller.stub!(:controller_name).and_return("posts") # for correct impressionable type in filter
|
||||
controller.stub!(:params).and_return({:id => impressionable.id.to_s}) # for correct impressionable id in filter
|
||||
controller.stub!(:session_hash).and_return("foo")
|
||||
controller.request.stub!(:remote_ip).and_return("1.2.3.4")
|
||||
controller.stub(:controller_name).and_return("posts") # for correct impressionable type in filter
|
||||
controller.stub(:params).and_return({:id => impressionable.id.to_s}) # for correct impressionable id in filter
|
||||
controller.stub(:session_hash).and_return("foo")
|
||||
controller.request.stub(:remote_ip).and_return("1.2.3.4")
|
||||
# order of the following methods is important for the test!
|
||||
controller.impressionist_subapp_filter(nil, [:ip_address, :request_hash, :session_hash])
|
||||
controller.impressionist(impressionable, nil, :unique => [:ip_address, :request_hash, :session_hash])
|
||||
|
|
|
@ -17,13 +17,13 @@ describe WidgetsController do
|
|||
end
|
||||
|
||||
it "should not log impression when user-agent is in wildcard list" do
|
||||
request.stub!(:user_agent).and_return('somebot')
|
||||
request.stub(:user_agent).and_return('somebot')
|
||||
get "show", :id=> 1
|
||||
Impression.all.size.should eq 11
|
||||
end
|
||||
|
||||
it "should not log impression when user-agent is in the bot list" do
|
||||
request.stub!(:user_agent).and_return('Acoon Robot v1.50.001')
|
||||
request.stub(:user_agent).and_return('Acoon Robot v1.50.001')
|
||||
get "show", :id=> 1
|
||||
Impression.all.size.should eq 11
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue