Skip to content

Instantly share code, notes, and snippets.

@richardking
Created February 20, 2014 23:29
Show Gist options
  • Select an option

  • Save richardking/9125546 to your computer and use it in GitHub Desktop.

Select an option

Save richardking/9125546 to your computer and use it in GitHub Desktop.
insta3 - controller spec
require 'spec_helper'
describe Admin::TeamStreamsController do
before do
activate_authlogic
end
it_should_behave_like "an action that requires admin login"
context "instagram accounts" do
before(:all) do
class InstagramAccount
alias_method :sync_following_old, :sync_following
alias_method :get_instagram_id_old, :get_instagram_id
def sync_following
end
def get_instagram_id
end
end
end
after(:all) do
class InstagramAccount
alias_method :sync_following, :sync_following_old
alias_method :get_instagram_id, :get_instagram_id_old
end
end
before(:each) do
@tag = FactoryGirl.create(:tag)
@account = FactoryGirl.build(:instagram_account, :tag_id => @tag.id)
end
it "should create an instagram account" do
lambda { post :create, :type => "instagram_accounts", :instagram_account => @account.attributes, :permalink => @tag.permalink }.
should change(InstagramAccount, :count).by(1)
end
it "should delete an instagram account" do
@account.save
lambda { get :destroy, :type => "instagram_accounts", :id => @account.id, :permalink => @tag.permalink }.
should change(InstagramAccount, :count).by(-1)
end
it "should disable an instagram account" do
@account.save
get :disable, :type => "instagram_accounts", :id => @account.id, :permalink => @tag.permalink
InstagramAccount.find(@account.id).import_enabled.should == false
end
it "should enable an instagram account" do
@account.save
@account.update_attribute(:import_enabled, false)
get :enable, :type => "instagram_accounts", :id => @account.id, :permalink => @tag.permalink
InstagramAccount.find(@account.id).import_enabled.should == true
end
end
context "twitter keywords" do
before(:each) do
@tag = FactoryGirl.create(:tag)
@twitter_keyword = FactoryGirl.create(:twitter_keyword, :tag_id => @tag.id)
end
it "should create a twitter keyword" do
keyword = "test"
lambda { post :create, :type => "twitter_keywords", :twitter_keyword => @twitter_keyword.attributes, :permalink => @tag.permalink }.
should change(TwitterKeyword, :count).by(1)
end
it "should show twitter keywords" do
get :show, :permalink => @tag.permalink
assigns(:positive_keywords).should == [@twitter_keyword]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment