Sha256: a45e27df89858f1f8ab971449b92bd64947b4bc64f62fb748e9e17d9a6b3f030

Contents?: true

Size: 1.82 KB

Versions: 59

Compression:

Stored size: 1.82 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 => cat,
                :published_at => published_at,
                :author => user,
                :starred => true
  end
EOF

rake 'db:seed'

Version data entries

59 entries across 59 versions & 4 rubygems

Version Path
activeadmin-0.6.6 spec/support/rails_template_with_data.rb
activeadmin-0.6.5 spec/support/rails_template_with_data.rb
activeadmin-0.6.4 spec/support/rails_template_with_data.rb
yousty-activeadmin-1.0.4.pre spec/support/rails_template_with_data.rb
yousty-activeadmin-1.0.3.pre spec/support/rails_template_with_data.rb
yousty-activeadmin-1.0.2.pre spec/support/rails_template_with_data.rb
activeadmin-0.6.3 spec/support/rails_template_with_data.rb
yousty-activeadmin-1.0.1.pre spec/support/rails_template_with_data.rb
yousty-activeadmin-1.0.0.pre spec/support/rails_template_with_data.rb
activeadmin-0.6.2 spec/support/rails_template_with_data.rb
activeadmin-0.6.1 spec/support/rails_template_with_data.rb
aa-rails4-0.6.0 spec/support/rails_template_with_data.rb
lalala-4.0.0.dev.141 vendor/deps/active_admin/spec/support/rails_template_with_data.rb
lalala-4.0.0.dev.136 vendor/deps/active_admin/spec/support/rails_template_with_data.rb
lalala-4.0.0.dev.135 vendor/deps/active_admin/spec/support/rails_template_with_data.rb
lalala-4.0.0.dev.134 vendor/deps/active_admin/spec/support/rails_template_with_data.rb
lalala-4.0.0.dev.133 vendor/deps/active_admin/spec/support/rails_template_with_data.rb
lalala-4.0.0.dev.132 vendor/deps/active_admin/spec/support/rails_template_with_data.rb
lalala-4.0.0.dev.131 vendor/deps/active_admin/spec/support/rails_template_with_data.rb
lalala-4.0.0.dev.129 vendor/deps/active_admin/spec/support/rails_template_with_data.rb