Created
September 5, 2011 13:59
-
-
Save tbbooher/1195052 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class PolcoGroupTest < ActiveSupport::TestCase | |
# Replace this with your real tests. | |
def setup | |
PolcoGroup.destroy_all | |
common_group = Fabricate(:polco_group, {:name => 'Dan Cole', :type => :common}) | |
@cali_group = Fabricate(:polco_group, {:name => 'CA', :type => :state}) | |
@ca46 = Fabricate(:polco_group, {:name => 'CA46', :type => :district}) | |
@user1 = Fabricate.build(:registered, {:joined_groups => [common_group, | |
@cali_group, | |
@ca46, | |
Fabricate(:polco_group, {:name => "Gang of 12", :type => :custom})]}) | |
end | |
test "should not allow an unapproved type" do | |
g = PolcoGroup.new | |
g.members << @user1 | |
g.name = "The Battle of Vienna (1683)" | |
g.type = :starhemberg | |
assert !g.valid? | |
assert_equal "Only valid groups are custom, state, district, common, country", g.errors.messages[:type].first | |
end | |
test "should force a unique name" do | |
g1 = PolcoGroup.new | |
g1.members << @user1 | |
g1.type = :custom | |
g1.name = "Grand Vizier Merzifonlu Kara Mustafa Pasha" | |
g1.save | |
assert g1.valid? | |
g2 = PolcoGroup.new | |
g2.members << @user1 | |
g2.type = :custom | |
g2.name = "Grand Vizier Merzifonlu Kara Mustafa Pasha" | |
assert !g2.valid? | |
assert_equal "is already taken", g2.errors.messages[:name].first | |
end | |
test "should allow a user to follow a group" do | |
g = PolcoGroup.new | |
g.type = :custom | |
g.name = 'Polco Founders' | |
g.followers << @user1 | |
assert_equal 1, g.followers.size | |
end | |
test "should add a user as a follower when a user follows the group" do | |
# remove all followers from the group | |
@cali_group.followers = [] | |
puts "hi" | |
# add @user to followed groups | |
@user1.followed_groups << @cali_group | |
# now check that it is there | |
assert_equal 1, @user1.followed_groups.count | |
@cali_group.reload | |
debugger | |
puts "followers count:#{@cali_group.followers.count}" | |
puts "first follower: #{@cali_group.followers.first}" | |
assert_equal nil, @cali_group.followers.first | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'simplecov' | |
SimpleCov.start do | |
add_filter "/test/" | |
end | |
require 'vcr_setup.rb' | |
#require 'webmock/test_unit' | |
#require 'vcr' | |
#VCR.config do |c| | |
# c.cassette_library_dir = 'fixtures/vcr_cassettes' | |
# c.stub_with :webmock | |
#end | |
require 'spork' | |
Spork.prefork do | |
ENV["RAILS_ENV"] = "test" | |
require File.expand_path('../../config/environment', __FILE__) | |
require 'rails/test_help' | |
include Devise::TestHelpers | |
require "#{Rails.root}" + '/lib/content_items/content_item.rb' | |
# maybe more needed | |
end | |
Spork.each_run do | |
# This code will be run each time you run your specs. | |
Dir[File.expand_path(File.join(File.dirname(__FILE__),'..','..', | |
'spec','factories','*.rb'))].each { |f| require f } | |
end | |
class ActiveSupport::TestCase | |
def load_all_sponsors | |
Legislator.update_legislators | |
end | |
def create_valid_user_with_id(id=nil) | |
begin | |
unless id.nil? | |
user = User.new( | |
:id => id, :email => 'tester@test.te', :name => 'nockenfell', | |
:password => 'secret', :password_confirmation => 'secret' | |
) | |
else | |
user = User.new( | |
:email => 'tester@test.te', :name => 'nockenfell', | |
:password => 'secret', :password_confirmation => 'secret' | |
) | |
end | |
user.save! | |
user | |
rescue | |
nil | |
end | |
end | |
def create_valid_user_with_roles_mask(role) | |
user = User.new( | |
:email => "#{role.to_s}@test.te", :name => role.to_s, | |
:password => 'secret', :password_confirmation => 'secret' | |
) | |
user.role=role | |
user.save! | |
user | |
end | |
def create_one_page(title='A Page', body='A Body') | |
Page.delete_all | |
Page.create title: title, body: body | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment