Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # app/models/carrier.rb
- class Carrier < ActiveRecord::Base
- has_many :accounts
- has_and_belongs_to_many :categories,
- :join_table => 'carriers_categories'
- validates_uniqueness_of :name, :server_key
- end
- # app/models/category.rb
- class Category < ActiveRecord::Base
- has_and_belongs_to_many :carriers,
- :join_table => 'carriers_categories'
- acts_as_list
- validates_presence_of :name
- validates_uniqueness_of :name
- def self.get_valid_categories(carrier_id)
- self.find :all,
- :include => :carriers,
- :conditions => {:carrier_id => carrier_id, :enabled => true},
- :order => "position"
- end
- end
- # text/fixtures/carrier.yml
- verizon:
- name: Verizon
- server_key: verizon
- created_at: <%= Time.now.to_s(:db) %>
- updated_at: <%= Time.now.to_s(:db) %>
- max_credits: 10
- allow_share_email: false
- allow_send_comment: false
- alltel:
- name: Alltel
- server_key: alltel
- created_at: <%= Time.now.to_s(:db) %>
- updated_at: <%= Time.now.to_s(:db) %>
- max_credits: 10
- allow_share_email: false
- allow_send_comment: false
- # test/fixtures/categories.yml
- celebrities:
- name: Celebrities
- enabled: true
- carriers: verizon
- verizon_ads:
- name: Verizon Ads
- enabled: true
- carriers: alltel
- # test/unit/category_test.rb
- require File.dirname(__FILE__) + '/../test_helper'
- class CategoryTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- fixtures :carriers, :categories
- def test_category_selection
- verzion = carriers(:verizon)
- alltel = carriers(:alltel)
- verizon_cats = Category.get_valid_categories(verzion.id)
- assert_equal 2, verizon_cats.length
- alltel_cats = Category.get_valid_categories(alltel.id)
- assert_equal 1, alltel_cats.length
- end
- end
- # Error when I run test
- [orion@OrionFoot dreamshots]$ ruby test/unit/category_test.rb
- Loaded suite test/unit/category_test
- Started
- E
- Finished in 0.19716 seconds.
- 1) Error:
- test_category_selection(CategoryTest):
- ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'categories.carrier_id' in 'where clause': SELECT `categories`.`id` AS t0_r0, `categories`.`name` AS t0_r1, `categories`.`position` AS t0_r2, `categories`.`enabled` AS t0_r3, `categories`.`created_at` AS t0_r4, `categories`.`updated_at` AS t0_r5, `carriers`.`id` AS t1_r0, `carriers`.`name` AS t1_r1, `carriers`.`server_key` AS t1_r2, `carriers`.`created_at` AS t1_r3, `carriers`.`updated_at` AS t1_r4, `carriers`.`max_credits` AS t1_r5, `carriers`.`allow_share_email` AS t1_r6, `carriers`.`allow_send_comment` AS t1_r7 FROM `categories` LEFT OUTER JOIN `carriers_categories` ON `carriers_categories`.category_id = `categories`.id LEFT OUTER JOIN `carriers` ON `carriers`.id = `carriers_categories`.carrier_id WHERE (`categories`.`carrier_id` = 144678685 AND `categories`.`enabled` = 1) ORDER BY position
- /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:150:in `log'
- /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/mysql_adapter.rb:281:in `execute'
- /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/mysql_adapter.rb:481:in `select'
- /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
- /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:55:in `select_all'
- /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations.rb:1242:in `select_all_rows'
- /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations.rb:1124:in `find_with_associations'
- /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations.rb:1122:in `catch'
- /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations.rb:1122:in `find_with_associations'
- /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1232:in `find_every'
- /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:503:in `find_without_pagination'
- /home/orion/code_work/dreamshots/vendor/plugins/paginating_find/lib/paginating_find.rb:103:in `find'
- /home/orion/code_work/dreamshots/app/models/category.rb:11:in `get_valid_categories'
- test/unit/category_test.rb:11:in `test_category_selection'
- /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/testing/default.rb:7:in `run'
- 1 tests, 0 assertions, 0 failures, 1 errors
Add Comment
Please, Sign In to add comment