小编pho*_*oet的帖子

angular mock`module`导致'[Object object]不是函数'

我正在尝试使用通过Teaspoon运行的Jasmine在Angular中创建一些单元测试.测试正在运行,但是我有一个简单的测试只是为了测试是否存在失败的控制器.我有以下测试设置.

//= require spec_helper

require("angular");
require("angular-mocks");
var app = require("./app");


describe("My App", function() {

  describe("App Controllers", function() {

    beforeEach(module("app"))

    it("Should have created an application controller", inject(function($rootScope, $controller){
      var scope = $rootScope.$new();
      ctrl = $controller("ApplicationCtrl", { $scope: scope });
    }));

  })

})
Run Code Online (Sandbox Code Playgroud)

需要的语句由Browserify处理,它处理我的依赖项,但我也可以挂钩我用于规范助手的链接.

在我需要的应用程序内部

require("angular");
var controllers = require("./controllers");

var app = angular.module("app", [
  "app.controllers"
]);

exports.app = app;
Run Code Online (Sandbox Code Playgroud)

当我运行此测试时,我得到以下错误

Failure/Error: TypeError: '[object Object]' is not a function (evaluating 'module("aialerts")')
Run Code Online (Sandbox Code Playgroud)

我花了很长时间试图解决这个问题,但我不知道发生了什么.任何帮助赞赏.

angularjs teaspoon angular-mock

25
推荐指数
2
解决办法
1万
查看次数

如何在Active Admin Rails 4中保存数组?

我在Rails 4中使用Active Admin.在我的模型中,我有一个字段是Postgres数组类型,当我创建它在后台传递的对象但它没有保存到数据库.那么我需要做什么来通过Active Admin将数组字段保存在数据库中.

谢谢

arrays model activeadmin ruby-2.0 ruby-on-rails-4

11
推荐指数
2
解决办法
5081
查看次数

如何使用ruby 1.9转换字​​符编码

我目前在亚马逊api的结果遇到问题.

该服务返回一个包含unicode字符的字符串:在Mac上学习Objective\xE2\x80\x93C(学习系列)

使用ruby 1.9.1,甚至无法处理字符串:

REXML::ParseException: #<Encoding::CompatibilityError: incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string)>

...

Exception parsing

Line: 1

Position: 1636

Last 80 unconsumed characters:

Learn Objective–C on the Mac (Learn Series)
Run Code Online (Sandbox Code Playgroud)

ruby encoding amazon

10
推荐指数
2
解决办法
2万
查看次数

从Gem添加到Rails autoload_path

我想编写一个将app/services目录添加到Rails应用程序的gem .

由于我想从Gem中添加它,我想出了这个解决方案:

class Railtie < ::Rails::Railtie
  config.after_initialize do |app|
    ::Rails.logger.info "adding #{ActiveService::Configuration.path} to autoload_path"
    app.config.autoload_paths = [ActiveService::Configuration.path] + app.config.autoload_paths
  end
end
Run Code Online (Sandbox Code Playgroud)

问题是这config.autoload_path是一个冻结的数组,因此修改它似乎不是一个好主意.

有关如何以更好的方式实现这一目标的任何建议?

gem load-path ruby-on-rails-3

8
推荐指数
1
解决办法
4048
查看次数

计算elasticsearch中的地理距离

我在我的查询中使用带轮胎geo_distance过滤器,它工作正常:

search.filter :geo_distance, :distance => "#{request.distance}km", :location => "#{request.lat},#{request.lng}"
Run Code Online (Sandbox Code Playgroud)

我希望结果会以某种方式包含我用于过滤器的地理位置的计算距离.

有没有办法告诉elasticsearch在响应中包含它,以便我不必为每个结果在ruby中计算它?

==更新==

我在谷歌小组中找到了答案:

search.sort do
  by "_geo_distance", "location" => "#{request.lat},#{request.lng}", "unit" => "km" if request.with_location?
end
Run Code Online (Sandbox Code Playgroud)

按原样排序_geo_distance会产生原始结果中的距离.

ruby geolocation elasticsearch

7
推荐指数
1
解决办法
4521
查看次数

github oauth有多个域名

我正在运行一个在多个子域usergroupXYZ.onruby.de上运行的应用程序,并且还支持任意域作为别名.因此,您可以通过yourusergroup.onruby.de或customdomain.de访问域.

该应用程序通过twitter oauth和github oauth2提供登录.

问题是,我没有找到通过自定义域支持github auth的方法.我总是redirect_uri_mismatch从github 得到错误.

twitter auth在重定向到其他域时没有问题.

除了为每个自定义域创建一个github应用程序令牌之外,有没有人能解决这个问题?

multi-tenant github-api oauth-2.0

7
推荐指数
1
解决办法
4315
查看次数

Rails 4 - 资产管道路径是'images/file.jpg'而不是'assets/file.jpg'

我一直在与Rails 4进行战斗,试图让它获取我的资产并创建正确的链接.通常,服务器重新启动和硬刷新的组合将使URL正确地通过,但并非总是如此. tmp:clear并且assetpipeline:clobber也不适合我.

问题在于image_path方法.我目前在自定义Form对象中,所以我这样做了:

class WalletForm
  include ActionView::Helpers::AssetUrlHelper

  def give_me_path
    image_path("logo.jpg")
  end
end
Run Code Online (Sandbox Code Playgroud)

image_path在开发和测试模式下给了我"images/logo.jpg".这应该是"assets/logo.jpg".我在过去已经注意到当rails无法找到图像时,它将使用images/logo.jpg而不是资产.我猜这是因为你把它放在管道之外的public/images文件夹中.但该文件确实存在app/assets/images,并且位于正确的位置.(我已经复制并粘贴了文件名,我也尝试重命名该文件.我重新启动了Web服务器,重新启动了pow)我甚至预先编译了资产,RAILS_ENV=test试图验证我的徽标是否被管道拾取, 假设

我不确定还有什么可以研究的.有什么建议?

ruby-on-rails asset-pipeline ruby-on-rails-4

5
推荐指数
0
解决办法
5712
查看次数

移动Safari中的文件上传和EXIF

正如这些问题所指出的,在某些情况下,iOS上的foto上传文件的地理位置和其他EXIF元数据已被删除(在野生动物园中):

https://apple.stackexchange.com/questions/326789/gps-exif-from-iphone-photo-upload-in-safari

从iPhone上传的图片会剥离EXIF数据

截至目前,我还没有找到适当的情况描述。我有2台设备用于测试安装了最新iOS的设备,其中未剥离EXIF元数据。

是否有办法确定(最好是在浏览器中或从上载中)是否已删除元数据以便向用户显示某种信息?

file-upload mobile-safari ios

5
推荐指数
1
解决办法
228
查看次数

Delayed Job DeserializationError, failed to load: allocator undefined for Proc

使用delayed_job_active_recordgem版本 4 ,我想延迟对外部 API 的请求。我的工作被添加到数据库中,并rake jobs:work运行它并将其从数据库中删除。但是,我的实际延迟代码messages_controller.rb从未执行过。

如果我尝试Delayed::Job.last.invoke_job在 rails 控制台中,我会收到以下错误:

Delayed::DeserializationError: Job failed to load: allocator undefined for Proc. Handler: "--- !ruby/object:Delayed::PerformableMethod\nobject: !ruby/object:MyApp::Zendesk\n  client: !ruby/object:ZendeskAPI::Client\n    config: !ruby/object:ZendeskAPI::Configuration\n      client_options: {}\n      cache: !ruby/object:ZendeskAPI::LRUCache\n        size: 1000\n        store: {}\n        lru: []\n      url: https://redacted.zendesk.com/api/v2\n      username: redacted\n      password: redacted\n      retry: true\n      logger: !ruby/object:Logger\n        progname: \n        level: 0\n        default_formatter: !ruby/object:Logger::Formatter\n          datetime_format: \n        formatter: \n        logdev: !ruby/object:Logger::LogDevice\n          shift_size: \n          shift_age: \n          filename: \n          dev: !ruby/object:IO {}\n          mutex: !ruby/object:Logger::LogDevice::LogDeviceMutex\n            mon_owner: \n            mon_count: …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails delayed-job

4
推荐指数
1
解决办法
2061
查看次数

将属性附加到模型以便在Rails 3上临时使用

我有一个用户模型=> @user

我想添加新属性current_time@user供临时使用.

不想进行迁移以添加列(仅供临时使用):

@user.current_time = Time.now
Run Code Online (Sandbox Code Playgroud)

有没有办法实现这个目标?

NoMethodError (undefined method `current_time=' for #<User:0x007fd6991e1050>):
  app/controllers/carts_controller.rb:47:in `block in search_user'
  app/controllers/carts_controller.rb:45:in `search_user'
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails

3
推荐指数
1
解决办法
1344
查看次数

为视图规范播种路径的正确方法

我正在用RSpec测试我的观点.由于一些变化,现在url_for在视图中调用了我为show动作编写的所有规范都失败了:

No route matches {:controller=>"events", :action=>"show"}
Run Code Online (Sandbox Code Playgroud)

:id部分缺失以及由于呼叫失败.

(我知道我可以将那个失败的方法调用存根)

我发现唯一的东西很旧,看起来像一个糟糕的解决方法.另外,RSpec的文件没有显示什么帮助.

有没有正确的方法告诉RSpec它应该是什么样的events/123

更多背景:

在视图中我调用了一个帮助器,如下所示:

def some_helper_method
  url_for(only_path: false)} + "something_else"
end
Run Code Online (Sandbox Code Playgroud)

对该方法的调用失败了

 Failure/Error: render
 ActionView::Template::Error:
   No route matches {:controller=>"events", :action=>"show"}
Run Code Online (Sandbox Code Playgroud)

我正在通过对该方法的调用进行存根来修复它 view.stub(some_helper_method: 'SOME_URL')

rspec-rails ruby-on-rails-4

3
推荐指数
1
解决办法
571
查看次数

在rails中测试控制器助手重定向

我试图在辅助模块上编写一个rspec单元测试

我有SessionsControllerSessionsHelper

里面SessionsHelper我有

def redirect_back_or(default)
  redirect_to(session[:return_to] || default)
  session.delete(:return_to)
end
Run Code Online (Sandbox Code Playgroud)

我想做一个看起来像这样的测试:

describe "redirect_back_or(default)" do
  describe "with stored location" do
    before do
      helper.request.path = users_path
      helper.store_location
    end
    it do 
      expect(helper.redirect_back_or(user_path(@user))).to redirect_to(users_url)
      helper.session[:return_to].should eq(nil) 
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

但我在Helper方法中得到一个例外

undefined method `redirect_to' for #<#<Class:0x00000006fc9940>:0x00000005322620>
# ./app/helpers/sessions_helper.rb:34:in `redirect_back_or'
# ./spec/helpers/sessions_helper_spec.rb:99:in `block (4 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)

ruby rspec ruby-on-rails

2
推荐指数
1
解决办法
1609
查看次数