Module: StandardAPI::TestCase::ClassMethods
- Defined in:
- lib/standard_api/test_case.rb
Class Method Summary collapse
Instance Method Summary collapse
- #controller_class ⇒ Object
- #model ⇒ Object
- #model=(val) ⇒ Object
- #normalize(*attributes, &block) ⇒ Object
Class Method Details
.extended(klass) ⇒ Object
156 157 158 |
# File 'lib/standard_api/test_case.rb', line 156 def self.extended(klass) klass.instance_variable_set('@normalizers', {}) end |
Instance Method Details
#controller_class ⇒ Object
160 161 162 163 164 165 |
# File 'lib/standard_api/test_case.rb', line 160 def controller_class controller_class_name = self.name.gsub(/Test$/, '') controller_class_name.constantize rescue NameError => e raise e if e. != "uninitialized constant #{controller_class_name}" end |
#model ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/standard_api/test_case.rb', line 175 def model return @model if defined?(@model) && @model klass_name = controller_class.name.gsub(/Controller$/, '').singularize begin @model = klass_name.constantize rescue NameError raise e unless e. =~ /uninitialized constant #{klass_name}/ end if @model.nil? raise "@model is nil: make sure you set it in your test using `self.model = ModelClass`." else @model end end |
#model=(val) ⇒ Object
167 168 169 170 171 172 173 |
# File 'lib/standard_api/test_case.rb', line 167 def model=(val) @model = val self.filters = val.attribute_names self.orders = val.attribute_names self.includes = val.reflect_on_all_associations.map(&:name) @model end |
#normalize(*attributes, &block) ⇒ Object
193 194 195 196 197 198 |
# File 'lib/standard_api/test_case.rb', line 193 def normalize(*attributes, &block) attributes.each do |attribute| @normalizers[model] ||= {} @normalizers[model][attribute] = block end end |