I am using rails 3.2.13 and ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-linux] in CentOS 5.6. When I try to seed the data I got the following error.
** Execute Samp:seed:record_status
Creating RecordStatus: Active
rake aborted!
ActiveRecord::RecordNotSaved
/usr/local/rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/persistence.rb:105:in `save!'
/usr/local/rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/validations.rb:56:in `save!'
/usr/local/rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/attribute_methods/dirty.rb:33:in `save!'
/usr/local/rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/transactions.rb:264:in `block in save!'
/opt/Samp/lib/tasks/seed/record_status.rake:19:in `block (4 levels) in <top (required)>'
/opt/Samp/lib/tasks/seed/record_status.rake:16:in `each'
/opt/Samp/lib/tasks/seed/record_status.rake:16:in `block (3 levels) in <top (required)>'
record_status.rake
16: record_statuses.each do |rs|
17: unless RecordStatus.find_by_seed_name(rs[:name])
18: puts "Creating RecordStatus: #{rs[:name]}"
19: RecordStatus.create!(:name => rs[:name],
20: :seed_name => rs[:name],
21: :description => rs[:description])
22: end
23: end
EDIT-1
*RecordStatus.rb*
class RecordStatus < ActiveRecord::Base
acts_as_enumerated
ACTIVE = 1
DISABLED = 2
DELETED = 3
validates_uniqueness_of :id , :name
end
It appears like you must have duplicate names in your seed data. To find out for sure, change your call to create! to something like:
rs = RecordStatus.new(...)
unless rs.save
raise "Couldn't save #{rs.inspect}: #{rs.errors.full_messages.to_sentence}"
end
Rails 3 doesn't support create/alter/destroy instances for enumerations by nature. If we wants to create any enumerations just add Model.enumeration_model_updates_permitted = true in record_status.rake file. REF : Enumerations_mixin
Related
Running rails test, Rails::TestUnitReporter is having trouble picking up the source location of MiniTest::Result tests. The structure of MiniTest::Result isn't what Rails::TestUnitReporter expects.
/usr/local/rvm/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb:71`:in `method': undefined method `test_It_calcualtes_late_fees_correctly' for class `Minitest::Result' (NameError)
Inserting a byebug call, I see:
[66, 75] in /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb
66: "%s#%s = %.2f s = %s" % [result.class, result.name, result.time, result.result_code]
67: end
68:
69: def format_rerun_snippet(result)
70: byebug if not Rails.env.production?
=> 71: location, line = result.method(result.name).source_location
72: "#{self.executable} #{relative_path_for(location)}:#{line}"
73: end
74:
75: def app_root
(byebug) results.first.source_location
["/home/xxx/code/prj/test/models/invoice_template_test.rb", 9]
My test:
4 class InvoiceTemplateTest < ActiveSupport::TestCase
5 test "the truth" do
6 assert true
7 end
8
9 test "It calcualtes late fees correctly" do
10 tests = {
11 fixed_fee: {
12 feePolicy: '10.0 $ > 50',
13 pastDue: 52.0,
[...]
25 },
26 decimal_fee: {
27 feePolicy: '0.1',
28 pastDue: 24.4,
29 expectedFee: 2.44,
30 },
31 }
32
33 tests.each {|scenario, parameters|
34 policy = parameters[:feePolicy]
35 it = InvoiceTemplate.new(late_fee: policy)
36
37 expected = parameters[:expectedFee]
38 actual = it.calculateLateFee(parameters[:pastDue])
39 msg = "For scenario #{scenario.to_s}, expected #{expected} and got #{actual}"
40 assert_in_delta(expected, actual, 0.001, msg)
41 }
42
43 end
44 end
If I comment out "It calcualtes late fees correctly", it runs "the truth" correctly:
$ rvm 2.3.1 do rails test
Running via Spring preloader in process 10308
Run options: --seed 37453
# Running:
.
Finished in 0.003080s, 324.6650 runs/s, 324.6650 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
$
It's not having trouble running the tests, it's having trouble reporting back cleanly from them. Inserting a test with assert false, I get same error:
9 test "the false" do
10 assert false
11 end
$ rvm 2.3.1 do rails test
Running via Spring preloader in process 16606
Run options: --seed 30320
# Running:
F
Failure:
InvoiceTemplateTest#test_the_false [/home/xxx/code/prj/test/models/invoice_template_test.rb:10]:
Expected false to be truthy.
[66, 75] in /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb
66: "%s#%s = %.2f s = %s" % [result.class, result.name, result.time, result.result_code]
67: end
68:
69: def format_rerun_snippet(result)
70: byebug if not Rails.env.production?
=> 71: location, line = result.method(result.name).source_location
72: "#{self.executable} #{relative_path_for(location)}:#{line}"
73: end
74:
75: def app_root
(byebug) c
/usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb:71:in `method': undefined method `test_the_false' for class `Minitest::Result' (NameError)
I don't think it's the double gems directory, it runs inside the same installation for the whole stack trace:
lusk 10:24:39 {t15209_railsUnitTest} ~/code/prj/test$ rvm 2.3.1 do rails test
Running via Spring preloader in process 11485
Run options: --seed 58861
# Running:
F
Failure:
InvoiceTemplateTest#test_It_calcualtes_late_fees_correctly [/home/xxx/code/prj/test/models/invoice_template_test.rb:40]:
For scenario minimum, expected 0.0 and got 10.0.
Expected |0.0 - 10.0| (10.0) to be <= 0.001.
[66, 75] in /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb
66: "%s#%s = %.2f s = %s" % [result.class, result.name, result.time, result.result_code]
67: end
68:
69: def format_rerun_snippet(result)
70: byebug if not Rails.env.production?
=> 71: location, line = result.method(result.name).source_location
72: "#{self.executable} #{relative_path_for(location)}:#{line}"
73: end
74:
75: def app_root
(byebug) c
/usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb:71:in `method': undefined method `test_It_calcualtes_late_fees_correctly' for class `Minitest::Result' (NameError)
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb:71:in `format_rerun_snippet'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb:23:in `record'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:803:in `block in record'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:802:in `each'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:802:in `record'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:334:in `run_one_method'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:321:in `block (2 levels) in run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:320:in `each'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:320:in `block in run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:360:in `on_signal'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:347:in `with_info_handler'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:319:in `run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/line_filtering.rb:9:in `run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:159:in `block in __run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:159:in `map'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:159:in `__run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:136:in `run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb:63:in `block in autorun'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/application.rb:171:in `serve'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
If I include rails_helper, I get more conflict, seemingly internal to rails:
$ rvmDo rails test
/usr/local/rvm/gems/ruby-2.3.1/gems/rails_helper-2.2.2/lib/rails_helper.rb:138:in `block in <class:Engine>': undefined method `install_helpers' for #<ActionDispatch::Routing::RouteSet:0x000000055c1b10>
Did you mean? instance_values (NoMethodError)
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.7/lib/active_support/lazy_load_hooks.rb:67:in `block in execute_hook'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.7/lib/active_support/lazy_load_hooks.rb:60:in `with_execution_control'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.7/lib/active_support/lazy_load_hooks.rb:65:in `execute_hook'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.7/lib/active_support/lazy_load_hooks.rb:50:in `block in run_load_hooks'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.7/lib/active_support/lazy_load_hooks.rb:49:in `each'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.7/lib/active_support/lazy_load_hooks.rb:49:in `run_load_hooks'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/application/finisher.rb:65:in `block in <module:Finisher>'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/initializable.rb:30:in `instance_exec'
I suppose the double stacked gem installation could be at the fault of incompatibiilty between MiniTest::Result and Rails::TestUnitReporter. But before I re-install my entire rvm, rails and ruby installation, is there any gem I should try to upgrade with bundle update --conservative gem-name ?
Update: Futher looking into what version and which gem of the two I'm running:
(byebug) list=
[66, 75] in /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.7/lib/rails/test_unit/reporter.rb
66: "%s#%s = %.2f s = %s" % [result.class, result.name, result.time, result.result_code]
67: end
68:
69: def format_rerun_snippet(result)
70: byebug if not Rails.env.production?
=> 71: location, line = result.method(result.name).source_location
72: "#{self.executable} #{relative_path_for(location)}:#{line}"
73: end
74:
75: def app_root
(byebug) Minitest::Result.singleton_methods.map{|m| Minitest::Result.method(m).source_location[0]}.uniq
["/usr/local/rvm/gems/ruby-2.3.1/gems/minitest-5.11.3/lib/minitest.rb", "/usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/core_ext.rb"]
So they are both from inside /usr/local/rvm/gems/ruby-2.3.1/ . I'm going to see if there are knonwn incompatibiilties between railties-5.0.7 and minitest-5.11.3 and determine which one I should upgrade.
I do not know why this is breaking. I'm trying to run a migration on some code I've inherited and I've hit a snag. Here is the error message followed by the migration file code.
== AddStorecreditGizmoType: migrating ========================================
rake aborted!
NoMethodError: undefined method `find_by_name' for GizmoCategory(id: integer, description: string):Class
/var/lib/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/base.rb:1876:in `method_missing'
/home/thefonso/site-dev/vendor/plugins/will_paginate/lib/will_paginate/finder.rb:175:in `method_missing_with_paginate'
db/migrate//20090628000954_add_storecredit_gizmo_type.rb:4:in `up'
/var/lib/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/migration.rb:282:in `block in migrate'
/var/lib/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/migration.rb:282:in `migrate'
/var/lib/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/migration.rb:365:in `migrate'
/var/lib/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/migration.rb:457:in `run'
/var/lib/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/migration.rb:409:in `run'
/var/lib/gems/1.9.1/gems/rails-2.3.14/lib/tasks/databases.rake:135:in `block (3 levels) in <top (required)>'
/var/lib/gems/1.9.1/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:migrate:up
(See full trace by running task with --trace)
Here is the migration file code
class AddStorecreditGizmoType < ActiveRecord::Migration
def self.up
# TODO: GizmoCategory.find_by_name("misc") is breaking...why? Attempted to replace with "where" but same error.
new = GizmoType.new(:name => "store_credit", :description => "Store Credit", :gizmo_category => GizmoCategory.find_by_name("misc"), :required_fee_cents => 0, :suggested_fee_cents => 0)
new.save!
DB.execute("UPDATE gizmo_contexts_gizmo_types SET gizmo_type_id = #{new.id} WHERE gizmo_type_id IN (SELECT id FROM gizmo_types WHERE name = 'gift_cert');")
end
def self.down
DB.execute("UPDATE gizmo_contexts_gizmo_types SET gizmo_type_id = (SELECT id FROM gizmo_types WHERE name = 'gift_cert') WHERE gizmo_type_id IN (SELECT id FROM gizmo_types WHERE name = 'store_credit');")
GizmoType.find_by_name("store_credit").destroy
end
end
I've tried using "where" and "Find_by" but I keep getting this same "undefined method blahblah for GizmoCategory
Can you point me in the right direction? What am I missing? forgetting? What's happening here?
Oh and versions are as follows
rails - 2.3.14
ruby - 1.9.3p194
Thanks
The find_by_* methods didn't exist in activerecord 2.3.14. Use Model.find instead.
category = GizmoCategory.find(:first, conditions: "name = 'store_credit'")
category.destroy if category
I am trying to test my application and I continually get the following error:
Error:
ContractsControllerTest#test_should_get_show:
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
Error:
ContractsControllerTest#test_should_get_show:
NoMethodError: undefined method `each' for nil:NilClass
Below is the code on my contract controller and I have similar code like this on all the controllers.
def index
#contract = Contract.all.paginate(page: params[:page], :per_page => 70)
end
def show
#contract = Contract.find(params[:id])
end
def new
#contract = Contract.new
end
def create
#contract = Contract.new(located)
if #contract.save
flash[:success] = "A record has been successfully added"
redirect_to contracts_path
else
render 'new'
end
end
def located
params.require(:contract).permit(:contract_name, :contract_status, :services_rendered, :contract_value, :award_year)
end
# editing a record in the contract from cotract table
def edit
#contract = Contract.find(params[:id])
end
def update
#contract = Contract.find(params[:id])
if #contract.update_attributes(located)
flash[:success] = "Contract form updated"
redirect_to contracts_path
else
render'edit'
end
end
def destroy
Contract.find(params[:id]).destroy
flash[:success] = "A record has been successfully deleted"
redirect_to contracts_path
end
Below is the full trace of the error when I run the command rails db:fixtures:load --trace
rails aborted!
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/fixture_set/file.rb:72:in `validate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/fixture_set/file.rb:49:in `raw_rows'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/fixture_set/file.rb:37:in `config_row'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/fixture_set/file.rb:27:in `model_class'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/fixtures.rb:791:in `block (2 levels) in
read_fixture_files'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/fixture_set/file.rb:15:in `open'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/fixtures.rb:790:in `block in read_fixture_files'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/fixtures.rb:789:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/fixtures.rb:789:in `each_with_object'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/fixtures.rb:789:in `read_fixture_files'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/fixtures.rb:598:in `initialize'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/fixtures.rb:529:in `new'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/fixtures.rb:529:in `block (2 levels) in
create_fixtures'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/fixtures.rb:526:in `map'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/fixtures.rb:526:in `block in create_fixtures'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/connection_adapters/postgresql/referential_integrity.rb: 22:in `disable_referential_integrity'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/fixtures.rb:523:in `create_fixtures'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-
5.0.5/lib/active_record/railties/databases.rake:207:in `block (3 levels) in
<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.0.5/lib/rails/commands/rake_proxy.rb:14:in `block in run_rake_task'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.0.5/lib/rails/commands/rake_proxy.rb:11:in `run_rake_task'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.0.5/lib/rails/commands/commands_tasks.rb:51:in `run_command!'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.0.5/lib/rails/commands.rb:18:in `<top (required)>'
/home/ubuntu/workspace/final_project/bin/rails:9:in `require'
/home/ubuntu/workspace/final_project/bin/rails:9:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/spring-
2.0.2/lib/spring/client/rails.rb:28:in `load'
/usr/local/rvm/gems/ruby-2.3.0/gems/spring-
2.0.2/lib/spring/client/rails.rb:28:in `call'
/usr/local/rvm/gems/ruby-2.3.0/gems/spring-
2.0.2/lib/spring/client/command.rb:7:in `call'
/usr/local/rvm/gems/ruby-2.3.0/gems/spring-2.0.2/lib/spring/client.rb:30:in
`run'
/usr/local/rvm/gems/ruby-2.3.0/gems/spring-2.0.2/bin/spring:49:in `<top
(required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/spring-
2.0.2/lib/spring/binstub.rb:31:in `load'
/usr/local/rvm/gems/ruby-2.3.0/gems/spring-
2.0.2/lib/spring/binstub.rb:31:in`<top (required)>'
/home/ubuntu/workspace/final_project/bin/spring:15:in `require'
/home/ubuntu/workspace/final_project/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:fixtures:load
(See full trace by running task with --trace)
My application containts 12 controllers, the same error occurs in each of the controllers. Also, I have 10 tables in my schema some of which contain references / relations to each other.
I don't really know what is wrong and I have be struggling with this problem for about four days now. I would be grateful if anyone could help me with any code or information that could help me to trace the source of the error. I would also be grateful if you could provide information for exactly where I should place the code to trace and solve this error.
Thanks
One of your fixture files in test/fixtures has bad formatting. The problem does not appear to be with your controllers or tests since it is happening for every single one of them. All of the fixtures get loaded into the test database before every single test, even if some are not used for the current test. So if there is an error in one of these files it will get raised for every test.
According to the line from the activerecord source that is throwing the error at the top of the stack trace you've provided, ActiveRecord is expecting every entry in your YAML fixture file to be a key which references a hash.
Each entry in a fixture should represent a model instance. The top level key is used as a name to reference that instance (rails usually names them one and two when generating the fixture template for a new model). Here is an example YAML fixture with one good entry and a few different types of bad ones.
# This will produce a hash associated to key :hash_entry.
# This is the correct type of entry, all others that follow are incorrect for rails fixtures.
hash_entry:
key1: value1
key2: value2
# This will produce the string "not a hash" associated to key :string_entry
string_entry: not a hash
# This will produce the array ["also", "not","a","hash"] associated to key :array_entry
array_entry:
- also
- not
- a
- hash
# This will produce nil associated to key :nil_entry
nil_entry:
You need to examine your fixtures files in test/fixtures and look for any that have the bad formatting as described above. Here is a rake task that will help you identify which files and entries need to be corrected. First run rails g task fixtures check_format, and place this code inside of the rake file that gets generated at lib/tasks/fixtures.rake.
namespace :fixtures do
desc "Looks for bad fixture files"
task check_format: :environment do
fixtures_dir = Rails.root.join("test", "fixtures")
fixture_files = Pathname.glob("#{fixtures_dir}/**/*.yml")
fixture_files.each do |file|
fixture = YAML.load(IO.read(file))
fixture.each_pair do |name, entry|
puts "Bad fixture entry #{name}: #{entry.inspect} in fixture #{file}" unless entry.is_a? Hash
end
end
end
end
Then run rails fixtures:check_format and the offending files and entries will be printed out on the command line for you to find and correct.
I'm not new to DynamoDB, but I'm new to DynamoID gem.
I can't achieve to make it work since I get the following error :
/aws-sdk-1.28.1/lib/aws/core/client.rb:366:in `return_or_raise': The action or operation requested is invalid. Verify that the action is typed correctly. (AWS::DynamoDB::Errors::InvalidAction)
/aws-sdk-1.28.1/lib/aws/core/client.rb:467:in `client_request'
(eval):3:in `list_tables'
/aws-sdk-1.28.1/lib/aws/dynamo_db/table_collection.rb:121:in `_each_item'
/aws-sdk-1.28.1/lib/aws/core/collection/with_limit_and_next_token.rb:54:in `_each_batch'
/aws-sdk-1.28.1/lib/aws/core/collection.rb:80:in `each_batch'
/aws-sdk-1.28.1/lib/aws/core/collection.rb:47:in `each'
/dynamoid-0.7.1/lib/dynamoid/adapter/aws_sdk.rb:185:in `collect'
/dynamoid-0.7.1/lib/dynamoid/adapter/aws_sdk.rb:185:in `list_tables'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:146:in `block (3 levels) in <module:Adapter>'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:39:in `benchmark'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:146:in `block (2 levels) in <module:Adapter>'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:25:in `block in reconnect!'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:39:in `benchmark'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:25:in `reconnect!'
/dynamoid-0.7.1/lib/dynamoid.rb:35:in `configure'
app/config/initializers/dynamoid.rb:1:in `<top (required)>'
It seems that list_tables doesn't exist, but it's a method of the AWS Ruby SDK
My model is very simple :
class Interaction
include Dynamoid::Document
table :name => :interactions, :key => :from, :read_capacity => 1, :write_capacity => 1
end
Could anybody help?
Cheers,
Emmanuel
The bug is many months old, here:
http://www.ruby-forum.com/topic/1094002
Two links in that which show code changes:
https://github.com/godfat/ruby/commit/f4e0e8f781b05c767ad2472a43a4ed0727a75708
https://github.com/godfat/ruby/commit/c7a6cf975d88828c2ed27d253f41c480f9b66ad6
I have Ruby 1.9.2 and rvm. I would have pasted those changes into the appropriate files, but I don't know how.
This worked a few days ago. I can't do Ruby on Rails commands like:
>> User.create :username => "a", :password => "a"
Here is the error message:
ArgumentError: wrong number of arguments(1 for 0)
from /Users/RedApple/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:48:in `method'
from /Users/RedApple/.rvm/rubies/ruby-1.9.2 p290/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:48:in `accept'
from /Users/RedApple/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:36:in `<<'
from /Users/RedApple/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:165:in `dump'
from /Users/RedApple/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/core_ext.rb:13:in `psych_to_yaml'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.0.4/lib/delayed/backend/base.rb:57:in `payload_object='
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/base.rb:2918:in `block in assign_attributes'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/base.rb:2914:in `each'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/base.rb:2914:in `assign_attributes'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/base.rb:2787:in `attributes='
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/base.rb:2477:in `initialize'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/base.rb:725:in `new'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/base.rb:725:in `create'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.0.4/lib/delayed/message_sending.rb:9:in `method_missing'
from /Users/RedApple/S/app/models/user.rb:29:in `block in <class:User>'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:182:in `call'
... 7 levels...
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/callbacks.rb:267:in `create_with_callbacks'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/base.rb:2927:in `create_or_update'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/callbacks.rb:250:in `create_or_update_with_callbacks'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/base.rb:2577:in `save'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/validations.rb:1089:in `save_with_validation'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/dirty.rb:79:in `save_with_dirty'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/transactions.rb:229:in `block in with_transaction_returning_status'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/transactions.rb:182:in `transaction'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/transactions.rb:228:in `with_transaction_returning_status'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/transactions.rb:196:in `block in save_with_transactions'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/transactions.rb:208:in `rollback_active_record_state!'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/transactions.rb:196:in `save_with_transactions'
from /Users/RedApple/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-2.3.14/lib/active_record/base.rb:727:in `create'
from (irb):1
from /Users/RedApple/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'>
Line 28-30 in user.rb:
after_create do |user|
user.delay( :priority => -15 ).seed
end
I am dead in the water without this. Can anyone help?
Delayed Job and the Ruby 1.9.2 YAML parser (Psych) are unfortunately not compatible.
Switch back to the previous YAML parser (Syck) by adding this to your config/application.rb, just below the call to Bundler.require:
YAML::ENGINE.yamler = "syck" if RUBY_VERSION >= "1.9.2"
You could patch your Ruby, but it's not easy and not really possible on managed hosts.
My solution was to create a monkeypatch based on the patch commit 31075.
Create an initializer file in your Rails project
config/initializers/psych_extensions.rb
and add this code:
# APPLIES RUBY PATCH REVISION 31075
module Psych
module Visitors
###
# YAMLTree builds a YAML ast given a ruby object. For example:
#
# builder = Psych::Visitors::YAMLTree.new
# builder << { :foo => 'bar' }
# builder.tree # => #<Psych::Nodes::Stream .. }
#
class YAMLTree < Psych::Visitors::Visitor
def accept target
# return any aliases we find
if node = #st[target.object_id]
node.anchor = target.object_id.to_s
return #emitter.alias target.object_id.to_s
end
if target.respond_to?(:to_yaml)
loc = target.public_method(:to_yaml).source_location.first
if loc !~ /(syck\/rubytypes.rb|psych\/core_ext.rb)/
unless target.respond_to?(:encode_with)
if $VERBOSE
warn "implementing to_yaml is deprecated, please implement \"encode_with\""
end
target.to_yaml(:nodump => true)
end
end
end
if target.respond_to?(:encode_with)
dump_coder target
else
send(#dispatch_cache[target.class], target)
end
end
private
# FIXME: remove this method once "to_yaml_properties" is removed
def find_ivars target
loc = target.public_method(:to_yaml_properties).source_location.first
unless loc.start_with?(Psych::DEPRECATED) || loc.end_with?('rubytypes.rb')
if $VERBOSE
warn "#{loc}: to_yaml_properties is deprecated, please implement \"encode_with(coder)\""
end
return target.to_yaml_properties
end
target.instance_variables
end
end
end
end