Sha256: 20a785b6ce3332a94ba5a65eb002a30e5e6c00f490a4a7d67aeff88e04b11a5d

Contents?: true

Size: 1.79 KB

Versions: 4

Compression:

Stored size: 1.79 KB

Contents

# Use the default
apply File.expand_path("../rails_template.rb", __FILE__)

# Register Active Admin controllers
%w{ Post User Category }.each do |type|
  generate :'active_admin:resource', type
end

scopes = <<-EOF
  scope :all, :default => true

  scope :drafts do |posts|
    posts.where(["published_at IS NULL"])
  end

  scope :scheduled do |posts|
    posts.where(["posts.published_at IS NOT NULL AND posts.published_at > ?", Time.now.utc])
  end

  scope :published do |posts|
    posts.where(["posts.published_at IS NOT NULL AND posts.published_at < ?", Time.now.utc])
  end

  scope :my_posts do |posts|
    posts.where(:author_id => current_admin_user.id)
  end

EOF
inject_into_file 'app/admin/posts.rb', scopes , :after => "ActiveAdmin.register Post do\n"

# Setup some default data
append_file "db/seeds.rb", <<-EOF
  users = ["Jimi Hendrix", "Jimmy Page", "Yngwie Malmsteen", "Eric Clapton", "Kirk Hammett"].collect do |name|
    first, last = name.split(" ")
    User.create!  :first_name => first,
                  :last_name => last,
                  :username => [first,last].join('-').downcase,
                  :age => rand(80)
  end

  categories = ["Rock", "Pop Rock", "Alt-Country", "Blues", "Dub-Step"].collect do |name|
    Category.create! :name => name
  end

  published_at_values = [Time.now.utc - 5.days, Time.now.utc - 1.day, nil, Time.now.utc + 3.days]

  1_000.times do |i|
    user = users[i % users.size]
    cat = categories[i % categories.size]
    published_at = published_at_values[i % published_at_values.size]
    Post.create :title => "Blog Post \#{i}",
                :body => "Blog post \#{i} is written by \#{user.username} about \#{cat.name}",
                :category_id => cat.id,
                :published_at => published_at,
                :author => user
  end
EOF

rake 'db:seed'

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activeadmin-axlsx-2.1.2 spec/support/rails_template_with_data.rb
activeadmin-axlsx-2.1.1 spec/support/rails_template_with_data.rb
activeadmin-axlsx-2.0.1 spec/support/rails_template_with_data.rb
activeadmin-axlsx-2.0.0 spec/support/rails_template_with_data.rb