Mam następujący kod:TypeError: niewłaściwy typ argumentu String (oczekiwane Module)
class ProfileLookup < ActiveRecord::Base
class << self
ProfileLookup.select("DISTINCT category").map{|c| c.category}.each do |category|
define_method("available_#{category.pluralize}".to_sym) do
ProfileLookup.where(category: category).order(:value).all.collect{|g| g.value}
end
end
end
end
które zasadniczo zawiera ładunek danych odnośników, podzielone na kategorie. Celem jest stworzenie metody dla każdej kategorii w bazie danych. Za pomocą konsoli Rails ten kod działa zgodnie z oczekiwaniami:
[email protected] :002 > ProfileLookup.available_genders
ProfileLookup Load (0.6ms) SELECT "profile_lookups".* FROM "profile_lookups" WHERE "profile_lookups"."category" = 'gender' ORDER BY value
=> ["Female", "Male"]
Jednak moje dane techniczne zawodzą. Poniższa specyfikacja:
require "spec_helper"
describe ProfileLookup do
its(:available_genders).should include("Male")
its(:available_age_groups).should include("0-17")
its(:available_interests).should include("Autos & Vehicles")
its(:available_countries).should include("United States")
end
nie powiedzie się z:
Exception encountered: #<TypeError: wrong argument type String (expected Module)>
backtrace:
/Users/fred/code/my_app/spec/models/profile_lookup_spec.rb:5:in `include'
jaki jest problem?
pokaż nam linię-włącz. gdziekolwiek to jest. –