Guest User

Untitled

a guest
Apr 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1. # app/models/carrier.rb
  2.  
  3. class Carrier < ActiveRecord::Base
  4. has_many :accounts
  5. has_and_belongs_to_many :categories,
  6. :join_table => 'carriers_categories'
  7.  
  8. validates_uniqueness_of :name, :server_key
  9. end
  10.  
  11. # app/models/category.rb
  12. class Category < ActiveRecord::Base
  13. has_and_belongs_to_many :carriers,
  14. :join_table => 'carriers_categories'
  15. acts_as_list
  16.  
  17. validates_presence_of :name
  18. validates_uniqueness_of :name
  19.  
  20.  
  21. def self.get_valid_categories(carrier_id)
  22. self.find :all,
  23. :include => :carriers,
  24. :conditions => {:carrier_id => carrier_id, :enabled => true},
  25. :order => "position"
  26. end
  27. end
  28.  
  29. # text/fixtures/carrier.yml
  30. verizon:
  31. name: Verizon
  32. server_key: verizon
  33. created_at: <%= Time.now.to_s(:db) %>
  34. updated_at: <%= Time.now.to_s(:db) %>
  35. max_credits: 10
  36. allow_share_email: false
  37. allow_send_comment: false
  38.  
  39. alltel:
  40. name: Alltel
  41. server_key: alltel
  42. created_at: <%= Time.now.to_s(:db) %>
  43. updated_at: <%= Time.now.to_s(:db) %>
  44. max_credits: 10
  45. allow_share_email: false
  46. allow_send_comment: false
  47.  
  48. # test/fixtures/categories.yml
  49. celebrities:
  50. name: Celebrities
  51. enabled: true
  52. carriers: verizon
  53.  
  54. verizon_ads:
  55. name: Verizon Ads
  56. enabled: true
  57. carriers: alltel
  58.  
  59. # test/unit/category_test.rb
  60. require File.dirname(__FILE__) + '/../test_helper'
  61.  
  62. class CategoryTest < ActiveSupport::TestCase
  63. # Replace this with your real tests.
  64. fixtures :carriers, :categories
  65.  
  66. def test_category_selection
  67. verzion = carriers(:verizon)
  68. alltel = carriers(:alltel)
  69.  
  70. verizon_cats = Category.get_valid_categories(verzion.id)
  71. assert_equal 2, verizon_cats.length
  72.  
  73. alltel_cats = Category.get_valid_categories(alltel.id)
  74. assert_equal 1, alltel_cats.length
  75. end
  76. end
  77.  
  78. # Error when I run test
  79. [orion@OrionFoot dreamshots]$ ruby test/unit/category_test.rb
  80. Loaded suite test/unit/category_test
  81. Started
  82. E
  83. Finished in 0.19716 seconds.
  84.  
  85. 1) Error:
  86. test_category_selection(CategoryTest):
  87. 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
  88. /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:150:in `log'
  89. /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/mysql_adapter.rb:281:in `execute'
  90. /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/mysql_adapter.rb:481:in `select'
  91. /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'
  92. /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'
  93. /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations.rb:1242:in `select_all_rows'
  94. /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations.rb:1124:in `find_with_associations'
  95. /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations.rb:1122:in `catch'
  96. /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations.rb:1122:in `find_with_associations'
  97. /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1232:in `find_every'
  98. /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:503:in `find_without_pagination'
  99. /home/orion/code_work/dreamshots/vendor/plugins/paginating_find/lib/paginating_find.rb:103:in `find'
  100. /home/orion/code_work/dreamshots/app/models/category.rb:11:in `get_valid_categories'
  101. test/unit/category_test.rb:11:in `test_category_selection'
  102. /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/testing/default.rb:7:in `run'
  103.  
  104. 1 tests, 0 assertions, 0 failures, 1 errors
Add Comment
Please, Sign In to add comment