Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoshiyuki Hirano authored and yhirano55 committed Nov 25, 2016
1 parent bbab6bb commit 3a3cd85
Show file tree
Hide file tree
Showing 22 changed files with 425 additions and 77 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
/coverage/
/doc/
/pkg/
/spec/rails/
/spec/reports/
/tmp/
/gemfiles/*.gemfile.lock
/gemfiles/vendor/
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ AllCops:
Exclude:
- "bin/*"
- "vendor/**/*"
- "gemfiles/**/*"
- "spec/rails/**/*"
- Gemfile
- Rakefile
DisplayCopNames: true
Expand Down
12 changes: 12 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
appraise 'rails42' do
gem 'rails', '~> 4.2.0'
gem "paper_trail", "~> 4.2.0"
gem 'activeadmin', '1.0.0.pre4'
end

appraise 'rails50' do
gem 'rails', '~> 5.0.0'
gem "paper_trail", "~> 5.2.2"
gem 'inherited_resources', github: 'activeadmin/inherited_resources'
gem 'activeadmin', github: 'activeadmin/activeadmin'
end
21 changes: 20 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in active_admin_versioning.gemspec
gemspec

gem "rails", "~> 5.0.0"
gem "paper_trail", "~> 5.2.2"
gem "inherited_resources", github: "activeadmin/inherited_resources"
gem "activeadmin", github: "activeadmin/activeadmin"
gem "pry"
gem 'appraisal'

group :development do
gem "rubocop", "~> 0.40.0"
end

group :test do
gem "capybara"
gem "rspec-rails"
gem "database_cleaner"
gem 'shoulda-matchers'
gem "sqlite3", platforms: :mri
gem "poltergeist"
end
9 changes: 5 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require 'bundler'
require 'rake'

RSpec::Core::RakeTask.new(:spec)
Bundler.setup
Bundler::GemHelper.install_tasks

task :default => :spec
FileList['tasks/**/*.rake'].each { |task| import task }
12 changes: 3 additions & 9 deletions active_admin_versioning.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- encoding: utf-8 -*-
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "active_admin_versioning/version"
require File.join(File.dirname(__FILE__), "lib", "active_admin_versioning", "version")

Gem::Specification.new do |gem|
gem.name = "active_admin_versioning"
Expand All @@ -21,12 +18,9 @@ Gem::Specification.new do |gem|

gem.required_ruby_version = ">= 2.1.0"

gem.add_runtime_dependency "activeadmin", ">= 1.0.0.pre4"
gem.add_runtime_dependency "paper_trail", ">= 4.2.0"
gem.add_dependency "activeadmin", ">= 1.0.0.pre4"
gem.add_dependency "paper_trail", ">= 4.2.0"

gem.add_development_dependency "bundler", "~> 1.13"
gem.add_development_dependency "rake", "~> 10.0"
gem.add_development_dependency "rspec", "~> 3.0"
gem.add_development_dependency "pry", "~> 0.10.0"
gem.add_development_dependency "rubocop", "~> 0.40.0"
end
2 changes: 2 additions & 0 deletions gemfiles/.bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
BUNDLE_DISABLE_SHARED_GEMS: "true"
25 changes: 25 additions & 0 deletions gemfiles/rails42.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 4.2.0"
gem "paper_trail", "~> 4.2.0"
gem "inherited_resources", :github => "activeadmin/inherited_resources"
gem "activeadmin", "1.0.0.pre4"
gem "pry"
gem "appraisal"

group :development do
gem "rubocop", "~> 0.40.0"
end

group :test do
gem "capybara"
gem "rspec-rails"
gem "database_cleaner"
gem "shoulda-matchers"
gem "sqlite3", :platforms => :mri
gem "poltergeist"
end

gemspec :path => "../"
25 changes: 25 additions & 0 deletions gemfiles/rails50.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 5.0.0"
gem "paper_trail", "~> 5.2.2"
gem "inherited_resources", :github => "activeadmin/inherited_resources"
gem "activeadmin", :github => "activeadmin/activeadmin"
gem "pry"
gem "appraisal"

group :development do
gem "rubocop", "~> 0.40.0"
end

group :test do
gem "capybara"
gem "rspec-rails"
gem "database_cleaner"
gem "shoulda-matchers"
gem "sqlite3", :platforms => :mri
gem "poltergeist"
end

gemspec :path => "../"
11 changes: 10 additions & 1 deletion lib/active_admin_versioning.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
require "active_admin"
require "paper_trail/version_concern"
require "active_admin_versioning/engine"
require "active_admin_versioning/version"
require "active_admin_versioning/active_admin/application"
require "active_admin_versioning/active_admin/dsl"
require "active_admin_versioning/active_admin/resource_controller"
require "active_admin_versioning/paper_trail/version_concern"

::ActiveAdmin::Application.send :prepend, ActiveAdminVersioning::ActiveAdmin::Application
::ActiveAdmin::DSL.send :include, ActiveAdminVersioning::ActiveAdmin::DSL
::PaperTrail::VersionConcern.send :include, ActiveAdminVersioning::PaperTrail::VersionConcern
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ActiveAdminVersioning
module Extension
module ActiveAdmin
module Application
def register(*arg, &block)
super(*arg) do
Expand Down
49 changes: 49 additions & 0 deletions lib/active_admin_versioning/active_admin/dsl.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module ActiveAdminVersioning
module ActiveAdmin
module DSL
def versioning
return unless enabled_paper_trail?

controller { include ActiveAdminVersioning::ActiveAdmin::ResourceController }

member_action(:versions) do
@versions = resource.versions.reorder(id: :desc, created_at: :desc).page(params[:page])
@page_title = ::PaperTrail::Version.model_name.human
render "versions"
end

with_options only: :show do
action_item :version do
link_to send("versions_admin_#{resource_instance_name}_path") do
::PaperTrail::Version.model_name.human
end
end

sidebar ::PaperTrail::Version.model_name.human do
if versions.present?
attributes_table_for versions[0] do
row ::PaperTrail::Version.model_name.human do |_|
version_number
end
row :event, &:event_i18n
row :whodunnit do |record|
record.whodunnit.presence || span(t("views.version.unknown_user"), class: "empty")
end
row :created_at
end
paginate versions, theme: :version
else
I18n.t("views.version.empty", model_name: ::PaperTrail::Version.model_name.human)
end
end
end
end

private

def enabled_paper_trail?
config.resource_class.try(:paper_trail).try(:enabled?) || config.resource_class.try(:paper_trail_enabled_for_model?)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ActiveAdminVersioning
module Extension
module ActiveAdmin
module ResourceController
def self.included(base)
base.before_action(:set_paper_trail_whodunnit)
Expand All @@ -16,7 +16,7 @@ def show
protected

def user_for_paper_trail
current_admin_user.try(:id) || t("views.version.unknown_user")
respond_to?(:current_admin_user) ? current_admin_user.id : t("views.version.unknown_user")
end
end
end
Expand Down
12 changes: 1 addition & 11 deletions lib/active_admin_versioning/engine.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
require "rails"
require "rails/engine"

module ActiveAdminVersioning
class Engine < ::Rails::Engine
config.after_initialize do
require "active_admin_versioning/extension/application"
require "active_admin_versioning/extension/dsl"
require "active_admin_versioning/extension/resource_controller"
require "active_admin_versioning/extension/paper_trail"

::ActiveAdmin::Application.send :prepend, ActiveAdminVersioning::Extension::Application
::ActiveAdmin::DSL.send :include, ActiveAdminVersioning::Extension::DSL
::PaperTrail::Version.send :include, ActiveAdminVersioning::Extension::PaperTrail
end
end
end
39 changes: 0 additions & 39 deletions lib/active_admin_versioning/extension/dsl.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "yaml"

module ActiveAdminVersioning
module Extension
module PaperTrail
module PaperTrail
module VersionConcern
def item_class
item_type.safe_constantize
end
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin_versioning/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActiveAdminVersioning
VERSION = "0.1.0".freeze
VERSION = "0.1.1".freeze
end
65 changes: 65 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require "spec_helper"

describe "integration test", type: :feature do
def random_word
"string".scan(/\w/).shuffle.join
end

def create_post
fill_in "post_title", with: random_word
fill_in "post_body", with: random_word
click_button "Create Post"
end

def update_post
fill_in "post_title", with: random_word
fill_in "post_body", with: random_word
click_button "Update Post"
end

describe "visit page of resource is enabled paper_trail" do
before do
visit "/admin/posts/new"
create_post

click_link "Edit Post"
update_post
end

describe "viewable registered content" do
let(:post) { Post.first }
let(:current_version) { post.versions.last }

it "should have elements are registered by dsl" do
within ".action_items" do
page.should have_link "Version", href: versions_admin_post_path(1)
end

within "#sidebar" do
page.should have_css "#version_sidebar_section"
page.should have_selector "#version_sidebar_section h3", text: "Version"
page.should have_selector "tr.row-version td", text: post.versions.size
page.should have_selector "tr.row-event td", text: current_version.event
page.should have_selector "tr.row-whodunnit td", text: current_version.whodunnit
end
end
end

describe "viewable versions page" do
let(:post) { Post.first }

before { click_link "Version" }

it "should have content" do
post.versions.each do |version|
within "#paper_trail_version_#{version.id}" do
page.should have_selector "td.col-id", text: version.id
page.should have_selector "td.col-whodunnit", text: version.whodunnit
page.should have_selector "td.col-event", text: version.event
page.should have_selector "td.col-item_type", text: version.item_type
end
end
end
end
end
end
Loading

0 comments on commit 3a3cd85

Please sign in to comment.