ruby 1.8 hash syntax for REE users. moving around some tests

This commit is contained in:
cowboycoded 2011-02-13 14:18:34 -05:00
parent 25193de04c
commit bc8a89278f
4 changed files with 33 additions and 12 deletions

View File

@ -16,26 +16,26 @@ describe ArticlesController do
end end
it "should log an impression without a message" do it "should log an impression without a message" do
get "show", id: 1 get "show", :id=> 1
Impression.all.size.should eq 11 Impression.all.size.should eq 11
Article.first.impressions.last.message.should eq nil Article.first.impressions.last.message.should eq nil
end end
it "should log the user_id if user is authenticated (@current_user before_filter method)" do it "should log the user_id if user is authenticated (@current_user before_filter method)" do
session[:user_id] = 123 session[:user_id] = 123
get "show", id: 1 get "show", :id=> 1
Article.first.impressions.last.user_id.should eq 123 Article.first.impressions.last.user_id.should eq 123
end end
it "should not log the user_id if user is authenticated" do it "should not log the user_id if user is authenticated" do
get "show", id: 1 get "show", :id=> 1
Article.first.impressions.last.user_id.should eq nil Article.first.impressions.last.user_id.should eq nil
end end
end end
describe PostsController do describe PostsController do
it "should log impression at the action level" do it "should log impression at the action level" do
get "show", id: 1 get "show", :id=> 1
Impression.all.size.should eq 11 Impression.all.size.should eq 11
Impression.last.controller_name.should eq "posts" Impression.last.controller_name.should eq "posts"
Impression.last.impressionable_type.should eq "Post" Impression.last.impressionable_type.should eq "Post"
@ -44,14 +44,14 @@ describe PostsController do
it "should log the user_id if user is authenticated (current_user helper method)" do it "should log the user_id if user is authenticated (current_user helper method)" do
session[:user_id] = 123 session[:user_id] = 123
get "show", id: 1 get "show", :id=> 1
Post.first.impressions.last.user_id.should eq 123 Post.first.impressions.last.user_id.should eq 123
end end
end end
describe WidgetsController do describe WidgetsController do
it "should log impression at the per action level" do it "should log impression at the per action level" do
get "show", id: 1 get "show", :id=> 1
Impression.all.size.should eq 11 Impression.all.size.should eq 11
get "index" get "index"
Impression.all.size.should eq 12 Impression.all.size.should eq 12
@ -61,13 +61,13 @@ describe WidgetsController do
it "should not log impression when user-agent is in wildcard list" do 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 get "show", :id=> 1
Impression.all.size.should eq 10 Impression.all.size.should eq 10
end end
it "should not log impression when user-agent is in the bot list" do 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 get "show", :id=> 1
Impression.all.size.should eq 10 Impression.all.size.should eq 10
end end
end end

View File

@ -2,11 +2,13 @@ require 'spec_helper'
describe Impressionist do describe Impressionist do
it "should be extended from ActiveRecord::Base" do it "should be extended from ActiveRecord::Base" do
ActiveRecord::Base.methods.include?(:is_impressionable).should be true method = RUBY_VERSION.match("1.8") ? "is_impressionable" : :is_impressionable
ActiveRecord::Base.methods.include?(method).should be true
end end
it "should include methods in ApplicationController" do it "should include methods in ApplicationController" do
ApplicationController.instance_methods.include?(:impressionist).should be true method = RUBY_VERSION.match("1.8") ? "impressionist" : :impressionist
ApplicationController.instance_methods.include?(method).should be true
end end
it "should include the before_filter method in ApplicationController" do it "should include the before_filter method in ApplicationController" do

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe Impression do describe Impression do
fixtures :articles,:impressions fixtures :articles,:impressions,:posts
before(:each) do before(:each) do
@article = Article.find(1) @article = Article.find(1)
@ -13,7 +13,7 @@ describe Impression do
end end
it "should save an impression with a message" do it "should save an impression with a message" do
@article.impressions.create(message:"test message") @article.impressions.create(:message=>"test message")
@article.impressions.last.message.should eq "test message" @article.impressions.last.message.should eq "test message"
end end

View File

@ -0,0 +1,19 @@
require 'spec_helper'
require 'systemu'
describe Impressionist do
fixtures :articles,:impressions,:posts
it "should delete existing migration and generate the migration file" do
migrations_dir = "#{Rails.root}/db/migrate"
impressions_migration = Dir.entries(migrations_dir).grep(/impressions/)[0]
File.delete("#{migrations_dir}/#{impressions_migration}") unless impressions_migration.blank?
generator_output = systemu("rails g impressionist")[1]
migration_name = generator_output.split("migrate/")[1].strip
Dir.entries(migrations_dir).include?(migration_name).should be true
end
it "should run the migration created in the previous spec" do
migrate_output = systemu("rake db:migrate")
migrate_output[1].include?("CreateImpressionsTable: migrated").should be true
end
end